結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-02-19 11:03:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 683 ms / 2,500 ms
コード長 1,421 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 212,648 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-02-19 11:03:27
合計ジャッジ時間 11,381 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
12,672 KB
testcase_01 AC 377 ms
23,552 KB
testcase_02 AC 554 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 108 ms
8,320 KB
testcase_07 AC 448 ms
43,008 KB
testcase_08 AC 415 ms
38,528 KB
testcase_09 AC 474 ms
43,520 KB
testcase_10 AC 597 ms
43,520 KB
testcase_11 AC 658 ms
43,520 KB
testcase_12 AC 631 ms
43,520 KB
testcase_13 AC 683 ms
43,520 KB
testcase_14 AC 635 ms
43,520 KB
testcase_15 AC 167 ms
6,676 KB
testcase_16 AC 165 ms
6,676 KB
testcase_17 AC 165 ms
6,676 KB
testcase_18 AC 216 ms
14,848 KB
testcase_19 AC 383 ms
34,176 KB
testcase_20 AC 369 ms
28,672 KB
testcase_21 AC 433 ms
43,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }
    vector<long long> w(10);
    for (int i = 0; i < 10; i++) {
        cin >> w[i];
    }
    vector<dsu> uf(1 << 10, dsu(n));
    vector<long long> cst(1 << 10);
    for (int st = 0; st < (1 << 10); st++) {
        for (int i = 0; i < 10; i++) {
            if (st & (1 << i)) {
                cst[st] += w[i];
            }
        }
        for (int i = 0; i < m; i++) {
            if ((st & (1 << c[a[i]])) && (st & (1 << c[b[i]]))) {
                uf[st].merge(a[i], b[i]);
            }
        }
    }
    int q;
    cin >> q;
    const long long INF = 9e18;
    while (q--) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        long long ans = INF;
        for (int st = 0; st < (1 << 10); st++) {
            if (uf[st].same(u, v)) {
                ans = min(ans, cst[st]);
            }
        }
        if (ans == INF) {
            cout << "-1\n";
        } else {
            cout << ans << "\n";
        }
    }
}
0