結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー shobonvipshobonvip
提出日時 2024-02-16 21:45:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,500 ms
コード長 1,783 bytes
コンパイル時間 4,523 ms
コンパイル使用メモリ 264,536 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-02-16 21:46:09
合計ジャッジ時間 9,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
6,548 KB
testcase_01 AC 223 ms
6,548 KB
testcase_02 AC 241 ms
6,548 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 113 ms
6,548 KB
testcase_07 AC 190 ms
6,548 KB
testcase_08 AC 193 ms
6,548 KB
testcase_09 AC 190 ms
6,548 KB
testcase_10 AC 257 ms
6,548 KB
testcase_11 AC 279 ms
6,548 KB
testcase_12 AC 258 ms
6,548 KB
testcase_13 AC 306 ms
6,548 KB
testcase_14 AC 261 ms
6,548 KB
testcase_15 AC 243 ms
6,548 KB
testcase_16 AC 238 ms
6,548 KB
testcase_17 AC 229 ms
6,548 KB
testcase_18 AC 115 ms
6,548 KB
testcase_19 AC 161 ms
6,548 KB
testcase_20 AC 145 ms
6,548 KB
testcase_21 AC 206 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n, m; cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i,0,m){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}

	vector<int> c(n);
	rep(i,0,n){
		cin >> c[i];
		c[i]--;
	}

	vector<ll> w(10);
	rep(i,0,10){
		cin >> w[i];
	}

	int q; cin >> q;
	vector<int> u(q), v(q);
	rep(i,0,q){
		cin >> u[i] >> v[i];
		u[i]--;
		v[i]--;
	}

	vector<ll> ans(q, 1e18);
	rep(i,0,1<<10){
		ll cost = 0;
		dsu uf(n);
		rep(j,0,10){
			if (i >> j & 1){
				cost += w[j];
			}
		}
		rep(j,0,m){
			if ((i>>c[a[j]]&1) && (i>>c[b[j]]&1)){
				uf.merge(a[j], b[j]);
			}
		}
		rep(j,0,q){
			if (uf.same(u[j], v[j])){
				chmin(ans[j], cost);
			}
		}
	}

	rep(i,0,q){
		if (ans[i] > 1e17){
			cout << "-1\n";
		} else{
			cout << ans[i] << '\n';
		}
	}
}

0