結果
| 問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2024-02-16 22:12:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 842 ms / 2,500 ms |
| コード長 | 1,288 bytes |
| コンパイル時間 | 2,190 ms |
| コンパイル使用メモリ | 204,592 KB |
| 最終ジャッジ日時 | 2025-02-19 14:04:52 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;
#include <atcoder/dsu>
int main() {
int N, M;
cin >> N >> M;
vector<pair<int, int>> E(M);
for (int i = 0; i < M; i++) {
cin >> E[i].first >> E[i].second;
E[i].first--;
E[i].second--;
}
vector<int> C(N);
for (int i = 0; i < N; i++) cin >> C[i], C[i]--;
vector<int> W(10);
for (int i = 0; i < 10; i++) cin >> W[i];
vector<atcoder::dsu> ds(1 << 10);
vector<ll> cost(1 << 10);
for (int i = 0; i < 1 << 10; i++) {
ds[i] = atcoder::dsu(N);
for (int j = 0; j < 10; j++) {
if (i >> j & 1) cost[i] += W[j];
}
for (int j = 0; j < M; j++) {
auto [u, v] = E[j];
if ((i >> C[u] & 1) && (i >> C[v] & 1)) {
ds[i].merge(u, v);
}
}
}
int Q;
cin >> Q;
while (Q--) {
int u, v;
cin >> u >> v;
u--;
v--;
ll ans = LLONG_MAX;
for (int i = 0; i < 1 << 10; i++) {
if (ds[i].same(u, v)) ans = min(ans, cost[i]);
}
if (ans == LLONG_MAX) ans = -1;
cout << ans << '\n';
}
}
Today03