結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー cho435cho435
提出日時 2024-02-16 22:00:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 809 ms / 2,500 ms
コード長 1,101 bytes
コンパイル時間 7,026 ms
コンパイル使用メモリ 305,140 KB
実行使用メモリ 44,032 KB
最終ジャッジ日時 2024-02-16 22:00:42
合計ジャッジ時間 16,940 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
12,800 KB
testcase_01 AC 451 ms
23,808 KB
testcase_02 AC 680 ms
40,320 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 123 ms
8,320 KB
testcase_07 AC 699 ms
43,392 KB
testcase_08 AC 670 ms
38,912 KB
testcase_09 AC 709 ms
44,032 KB
testcase_10 AC 769 ms
44,032 KB
testcase_11 AC 745 ms
44,032 KB
testcase_12 AC 809 ms
44,032 KB
testcase_13 AC 775 ms
44,032 KB
testcase_14 AC 735 ms
44,032 KB
testcase_15 AC 141 ms
6,548 KB
testcase_16 AC 141 ms
6,548 KB
testcase_17 AC 138 ms
6,548 KB
testcase_18 AC 268 ms
14,976 KB
testcase_19 AC 481 ms
34,560 KB
testcase_20 AC 411 ms
28,928 KB
testcase_21 AC 519 ms
44,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

using atcoder::dsu;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--; b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
	vector<int> c(n);
	rep(i,n) cin>>c.at(i);
	rep(i,n) c.at(i)--;
	vector<int> w(10);
	rep(i,10) cin>>w.at(i);
	vector<dsu> d(1<<10,dsu(n));
	vector<ll> sc(1<<10,0);
	rep(bit,1<<10){
		dsu &uf=d.at(bit);
		rep(x,n){
			if((bit>>c.at(x))&1){
				for(int y:g.at(x)){
					if((bit>>c.at(y))&1){
						uf.merge(x,y);
					}
				}
			}
		}
		rep(i,10){
			if((bit>>i)&1) sc.at(bit)+=w.at(i);
		}
	}
	int q;
	cin>>q;
	rep(Qi,q){
		int u,v;
		cin>>u>>v;
		u--; v--;
		ll ans=1e18;
		rep(bit,1<<10){
			if(d.at(bit).same(u,v)){
				ans=min(ans,sc.at(bit));
			}
		}
		if(ans==1e18) ans=-1;
		cout<<ans<<'\n';
	}
}
0