結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー kokoseikokosei
提出日時 2024-02-16 23:07:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,198 bytes
コンパイル時間 4,857 ms
コンパイル使用メモリ 257,340 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-16 23:08:17
合計ジャッジ時間 6,495 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using ll = long long;
ll inf = 1e18;

int N, M, Q;
int C[1010];
ll W[10];
int A[1010], B[1010];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N >> M;
    for(int i = 0;i < M;i++){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    for(int i = 0;i < N;i++){
        cin >> C[i];
        C[i]--;
    }
    for(int i = 0;i < 10;i++)cin >> W[i];
    vector<pair<ll, atcoder::dsu>> ufs;
    for(int i = 0;i < 1 << 10;i++){
        ll cost = 0;
        for(int j = 0;j < 10;j++){
            if(i >> j & 1)cost += W[j];
        }
        atcoder::dsu uf(N);
        for(int j = 0;j < M;j++){
            if(i >> C[A[j]] & i >> C[B[j]] & 1){
                uf.merge(A[j], B[j]);
            }
        }
        ufs.push_back({cost, uf});
    }
    cin >> Q;
    while(Q--){
        int u, v; cin >> u >> v;
        u--, v--;
        ll ans = inf;
        for(int i = 0;i < 1 << 10;i++){
            auto [c, uf] = ufs[i];
            if(uf.same(u, v)){
                ans = min(ans, c);
            }
        }
        cout << (ans == inf ? -1 : ans) << endl;
    }
    return 0;
}
0