結果
| 問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-11 16:55:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 734 ms / 2,500 ms |
| コード長 | 884 bytes |
| コンパイル時間 | 2,578 ms |
| コンパイル使用メモリ | 206,452 KB |
| 最終ジャッジ日時 | 2025-02-19 05:09:28 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
using ll=long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<array<int,2>>E(M);
for(auto &i:E){
cin>>i[0]>>i[1];
--i[0],--i[1];
}
vector C(N,0);
for(int &i:C)cin>>i,--i;
vector W(10,0ll);
for(ll &i:W)cin>>i;
vector G(1<<10,atcoder::dsu(N));
for(int i=0;i<1<<10;i++){
for(auto j:E){
if((i>>C[j[0]])&(i>>C[j[1]])&1){
G[i].merge(j[0],j[1]);
}
}
}
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;
while(Q--){
int U,V;
cin>>U>>V;
--U,--V;
ll ans=1e12;
for(int i=0;i<1<<10;i++){
if(G[i].same(U,V)){
ans=min(ans,cost[i]);
}
}
if(ans==1e12)ans=-1;
cout<<ans<<'\n';
}
}