結果

問題 No.1812 Uribo Road
ユーザー ぷらぷら
提出日時 2022-01-14 22:17:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,333 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 213,976 KB
実行使用メモリ 174,600 KB
最終ジャッジ日時 2024-04-30 15:22:57
合計ジャッジ時間 8,921 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 10 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 20 ms
6,944 KB
testcase_09 AC 39 ms
6,944 KB
testcase_10 AC 14 ms
6,940 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

bool chmin(int &x,int y) {
    if(x > y) {
        x = y;
        return true;
    }
    return false;
}

int main() {
    int N,M,K;
    cin >> N >> M >> K;
    vector<int>R(K);
    for(int i = 0; i < K; i++) {
        cin >> R[i];
        R[i]--;
    }
    vector<vector<array<int,3>>>road(N);
    for(int i = 0; i < M; i++) {
        int A,B,C;
        cin >> A >> B >> C;
        A--;
        B--;
        int id = -1;
        for(int j = 0; j < K; j++) {
            if(R[j] == i) {
                id = j;
            }
        }
        road[A].push_back({B,C,id});
        road[B].push_back({A,C,id});
    }
    vector<vector<int>>dist(N,vector<int>(1 << K,1001001001));
    priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>>que;
    dist[0][0] = 0;
    que.push({0,0,0});
    while (!que.empty()) {
        auto x = que.top();
        que.pop();
        if(dist[x[1]][x[2]] != x[0]) {
            continue;
        }
        for(auto i:road[x[1]]) {
            int to1 = i[0];
            int to2 = x[2];
            if(i[2] != -1) {
                to2 |= (1 << i[2]);
            }
            if(chmin(dist[to1][to2],i[1]+x[0])) {
                que.push({i[1]+x[0],to1,to2});
            }
        }
    }
    cout << dist[N-1][(1 << K)-1] << endl;
}
0