結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー kokoseikokosei
提出日時 2024-02-16 23:14:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,266 bytes
コンパイル時間 3,832 ms
コンパイル使用メモリ 271,804 KB
実行使用メモリ 30,356 KB
最終ジャッジ日時 2024-02-16 23:14:45
合計ジャッジ時間 10,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

int N, M, Q;
int C[10101];
ll W[10];
int A[10101], B[10101];
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