結果

問題 No.1812 Uribo Road
ユーザー nawawannawawan
提出日時 2022-01-14 22:42:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,165 bytes
コンパイル時間 2,609 ms
コンパイル使用メモリ 213,768 KB
実行使用メモリ 172,692 KB
最終ジャッジ日時 2023-08-12 21:13:05
合計ジャッジ時間 9,351 ms
ジャッジサーバーID
(参考情報)
judge7 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 11 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 20 ms
4,384 KB
testcase_09 AC 41 ms
4,384 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 9 ms
4,380 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;
struct edge{
    int to;
    int cost;
    int i;
};
typedef tuple<int, int, int> P;
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<edge>> G(N);
    vector<int> t(M, -1);
    for(int i = 0; i < K; i++) t[R[i]] = i;
    for(int i = 0; i < M; i++){
        int A, B, C;
        cin >> A >> B >> C;
        A--;
        B--;
        G[A].push_back({B, C, i});
        G[B].push_back({A, C, i});
    }
    int INF = 1000000000;
    vector<vector<int>> d(N, vector<int>(1 << K, INF));
    d[0][0] = 0;

    priority_queue<P, vector<P>, greater<P>> q;
    q.push({0, 0, 0});
    while(!q.empty()){
        auto [dis, now, bit] = q.top();
        q.pop();
        if(d[now][bit] > dis) continue;
        for(auto [to, cost, i] : G[now]){
            int b = bit;
            if(t[i] != -1) b |= (1 << t[i]);
            if(d[to][b] > dis + cost){
                d[to][b] = dis + cost;
                q.push({d[to][b], to, b});
            }
        }
    }
    cout << d[N - 1][(1 << K) - 1] << endl;
}
0