結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー 👑 hitonanodehitonanode
提出日時 2024-02-17 10:53:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 829 ms / 2,500 ms
コード長 1,239 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 107,512 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-02-17 10:53:45
合計ジャッジ時間 11,920 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
12,672 KB
testcase_01 AC 484 ms
23,552 KB
testcase_02 AC 689 ms
39,808 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 107 ms
8,320 KB
testcase_07 AC 617 ms
42,880 KB
testcase_08 AC 569 ms
38,528 KB
testcase_09 AC 632 ms
43,520 KB
testcase_10 AC 756 ms
43,520 KB
testcase_11 AC 803 ms
43,520 KB
testcase_12 AC 829 ms
43,520 KB
testcase_13 AC 763 ms
43,520 KB
testcase_14 AC 802 ms
43,520 KB
testcase_15 AC 176 ms
6,676 KB
testcase_16 AC 177 ms
6,676 KB
testcase_17 AC 176 ms
6,676 KB
testcase_18 AC 294 ms
14,848 KB
testcase_19 AC 492 ms
34,176 KB
testcase_20 AC 444 ms
28,672 KB
testcase_21 AC 543 ms
43,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

#include <atcoder/dsu>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<pair<int, int>> edges(M);
    for (auto &[a, b] : edges) cin >> a >> b, --a, --b;

    vector<int> C(N);
    for (auto &c : C) cin >> c, --c;

    constexpr int D = 10;

    vector<long long> W(D);
    for (auto &w : W) cin >> w;

    vector<long long> Wsum(1 << D);
    for (int S = 0; S < (1 << D); ++S) {
        for (int i = 0; i < D; ++i) {
            if (S & (1 << i)) Wsum.at(S) += W.at(i);
        }
    }

    vector<atcoder::dsu> dsus(1 << D);
    for (int S = 0; S < (1 << D); ++S) {
        dsus.at(S) = atcoder::dsu(N);
        for (auto [a, b] : edges) {
            if ((S & 1 << C.at(a)) and (S & 1 << C.at(b))) dsus.at(S).merge(a, b);
        }
    }

    int Q;
    cin >> Q;

    constexpr long long inf = 1e18;

    while (Q--) {
        int u, v;
        cin >> u >> v;
        --u, --v;

        long long best = inf;
        for (int S = 0; S < (1 << D); ++S) {
            if (dsus.at(S).same(u, v)) best = min(best, Wsum.at(S));
        }

        if (best == inf) best = -1;

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