結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー 沙耶花沙耶花
提出日時 2024-02-16 21:57:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,500 ms
コード長 985 bytes
コンパイル時間 4,561 ms
コンパイル使用メモリ 264,664 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-16 21:57:41
合計ジャッジ時間 10,126 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
6,676 KB
testcase_01 AC 262 ms
6,676 KB
testcase_02 AC 262 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 138 ms
6,676 KB
testcase_07 AC 224 ms
6,676 KB
testcase_08 AC 213 ms
6,676 KB
testcase_09 AC 228 ms
6,676 KB
testcase_10 AC 305 ms
6,676 KB
testcase_11 AC 306 ms
6,676 KB
testcase_12 AC 332 ms
6,676 KB
testcase_13 AC 307 ms
6,676 KB
testcase_14 AC 305 ms
6,676 KB
testcase_15 AC 286 ms
6,676 KB
testcase_16 AC 284 ms
6,676 KB
testcase_17 AC 283 ms
6,676 KB
testcase_18 AC 144 ms
6,676 KB
testcase_19 AC 192 ms
6,676 KB
testcase_20 AC 175 ms
6,676 KB
testcase_21 AC 219 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001



int main(){
	
	int n,m;
	cin>>n>>m;
	
	vector<int> a(m),b(m);
	rep(i,m){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
	}
	
	vector<int> c(n);
	rep(i,n){
		cin>>c[i];
		c[i]--;
	}
	vector<long long> w(10);
	rep(i,10)cin>>w[i];
	int q;
	cin>>q;
	vector<long long> ans(q,Inf64);
	
	vector<int> u(q),v(q);
	rep(i,q){
		cin>>u[i]>>v[i];
		u[i]--,v[i]--;
	}
	
	rep(i,1<<10){
		dsu D(n);
		rep(j,m){
			if((i>>c[a[j]])&1){
				if((i>>c[b[j]])&1)D.merge(a[j],b[j]);
			}
		}
		long long cost  = 0;
		rep(j,10){
			if((i>>j)&1)cost += w[j];
		}
		rep(j,q){
			if(D.same(u[j],v[j])&&((i>>c[u[j]])&1)&&((i>>c[v[j]])&1))ans[j] = min(ans[j],cost);
			
		}
	}
	rep(i,q){
		long long aa = ans[i];
		if(aa==Inf64)aa = -1;
		cout<<aa<<endl;
	}
	
	return 0;
}
0