結果

問題 No.1812 Uribo Road
ユーザー 👑 rin204rin204
提出日時 2022-01-20 22:48:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,257 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 222,584 KB
実行使用メモリ 334,644 KB
最終ジャッジ日時 2024-05-03 09:41:57
合計ジャッジ時間 9,124 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 15 ms
5,376 KB
testcase_09 AC 30 ms
5,376 KB
testcase_10 AC 12 ms
5,376 KB
testcase_11 AC 6 ms
5,376 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;
const long long inf = 1LL << 60;

struct G{
    int npos;
    long long c;
    int dbit;
};

struct HQ{
    long long d;
    int pos;
    int bit;
    
    bool operator<(const HQ& right) const{
        return d > right.d;
    }
};

int main(void){
    int n, m, k;
    cin >> n >> m >> k;
    map<int, int> R;
    int r;
    for(int i = 0; i < k; i++){
        cin >> r;
        R[r - 1] = 1 << i;
    }
    vector<vector<G>> edges(n, vector<G>());
    int a, b, c, d;
    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        a--; b--;
        edges[a].push_back({b, c, R[i]});
        edges[b].push_back({a, c, R[i]});
    }
    vector<vector<long long>> dist(n, vector<long long>(1 << k, inf));
    dist[0][0] = 0;
    priority_queue<HQ> hq;
    hq.push({0, 0, 0});
    while(!hq.empty()){
        auto a = hq.top();
        hq.pop();
        if(a.d > dist[a.pos][a.bit]) continue;
        for(auto b: edges[a.pos]){
            int nbit = a.bit | b.dbit;
            if(dist[b.npos][nbit] > b.c + a.d){
                dist[b.npos][nbit] = b.c + a.d;
                hq.push({b.c + a.d, b.npos, nbit});
            }
        }
        
    }
    cout << dist[n - 1][(1 << k) - 1] << "\n";
    
}
0