結果
問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
ユーザー |
|
提出日時 | 2024-02-11 17:50:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,099 bytes |
コンパイル時間 | 2,305 ms |
コンパイル使用メモリ | 205,264 KB |
最終ジャッジ日時 | 2025-02-19 05:15:30 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 21 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; // TLE int main(){ int N,M; cin>>N>>M; vector G(N,vector(0,0)); for(int i=0;i<M;i++){ int A,B; cin>>A>>B; --A,--B; G[A].push_back(B); G[B].push_back(A); } vector C(N,0); for(int &i:C)cin>>i,--i; vector W(10,0ll); for(ll &i:W)cin>>i; vector cost(1<<10,0ll); for(int i=0;i<1<<10;i++){ for(int j=0;j<10;j++){ if(i>>j&1)cost[i]+=W[j]; } } int Q; cin>>Q; vector dp(1<<10,vector(N,Q)); while(Q--){ int U,V; cin>>U>>V; --U,--V; ll ans=-1; auto comp=[&](array<int,2> a,array<int,2> b){ return cost[a[0]]>cost[b[0]]; }; priority_queue<array<int,2>,vector<array<int,2>>,decltype(comp)> pq(comp); dp[1<<C[U]][U]=Q; pq.push({1<<C[U],U}); while(pq.size()){ auto [s,v]=pq.top(); pq.pop(); if(v==V){ ans=cost[s]; break; } for(int i:G[v]){ if(dp[s|(1<<C[i])][i]>Q){ dp[s|(1<<C[i])][i]=Q; pq.push({s|(1<<C[i]),i}); } } } cout<<ans<<'\n'; } }