結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー Today03Today03
提出日時 2024-02-16 22:09:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,248 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 213,368 KB
実行使用メモリ 43,776 KB
最終ジャッジ日時 2024-02-16 22:09:33
合計ジャッジ時間 13,367 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
12,928 KB
testcase_01 AC 493 ms
23,808 KB
testcase_02 AC 718 ms
40,064 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 163 ms
8,576 KB
testcase_07 AC 612 ms
43,136 KB
testcase_08 AC 628 ms
38,784 KB
testcase_09 AC 618 ms
43,776 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 177 ms
6,676 KB
testcase_16 AC 184 ms
6,676 KB
testcase_17 AC 176 ms
6,676 KB
testcase_18 AC 330 ms
15,104 KB
testcase_19 AC 494 ms
34,432 KB
testcase_20 AC 462 ms
28,800 KB
testcase_21 AC 534 ms
43,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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]);
        }

        cout << ans << '\n';
    }
}
0