結果

問題 No.1812 Uribo Road
ユーザー ぷら
提出日時 2022-01-14 22:17:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,333 bytes
コンパイル時間 2,493 ms
コンパイル使用メモリ 206,360 KB
最終ジャッジ日時 2025-01-27 11:41:34
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

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