結果

問題 No.807 umg tours
ユーザー recososorecososo
提出日時 2020-03-06 14:48:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 598 ms / 4,000 ms
コード長 1,436 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 182,716 KB
実行使用メモリ 23,472 KB
最終ジャッジ日時 2024-05-03 00:11:25
合計ジャッジ時間 9,614 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 299 ms
13,056 KB
testcase_12 AC 332 ms
14,784 KB
testcase_13 AC 433 ms
16,752 KB
testcase_14 AC 186 ms
9,864 KB
testcase_15 AC 137 ms
8,280 KB
testcase_16 AC 459 ms
16,988 KB
testcase_17 AC 596 ms
22,944 KB
testcase_18 AC 598 ms
22,944 KB
testcase_19 AC 562 ms
19,964 KB
testcase_20 AC 356 ms
14,848 KB
testcase_21 AC 374 ms
15,312 KB
testcase_22 AC 147 ms
8,576 KB
testcase_23 AC 106 ms
7,296 KB
testcase_24 AC 319 ms
22,568 KB
testcase_25 AC 597 ms
23,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
int main(){
    int n,m;cin >> n >> m;
    vector<vector<pair<int,int>>> g(n);
    for(int i=0;i<m;i++){
        int a,b,c;cin >> a >> b >> c;
        a--,b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    vector<vector<ll>> d(n,vector<ll>(2,INF));
    d[0][0]=0;
    priority_queue<pair<pair<ll,int>,int>,vector<pair<pair<ll,int>,int>>,greater<pair<pair<ll,int>,int>>> pq;
    pq.push({{0,0},0});
    while(!pq.empty()){
        ll u=pq.top().first.first;
        int v=pq.top().first.second,w=pq.top().second;
        pq.pop();
        if(u>d[v][w]){
            continue;
        }
        for(auto x:g[v]){
            if(d[x.first][w]>d[v][w]+x.second){
                d[x.first][w]=d[v][w]+x.second;
                pq.push({{d[x.first][w],x.first},w});
            }
            if(!w){
                if(d[x.first][1]>d[v][0]){
                    d[x.first][1]=d[v][0];
                    pq.push({{d[x.first][1],x.first},1});
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        if(i){
            cout << d[i][0]+d[i][1] << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
}
0