結果

問題 No.807 umg tours
ユーザー betrue12betrue12
提出日時 2019-03-22 22:02:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 4,000 ms
コード長 1,165 bytes
コンパイル時間 2,589 ms
コンパイル使用メモリ 204,868 KB
実行使用メモリ 45,244 KB
最終ジャッジ日時 2023-08-15 11:58:10
合計ジャッジ時間 8,180 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,164 KB
testcase_01 AC 4 ms
8,212 KB
testcase_02 AC 4 ms
8,244 KB
testcase_03 AC 4 ms
8,264 KB
testcase_04 AC 4 ms
8,360 KB
testcase_05 AC 3 ms
8,252 KB
testcase_06 AC 4 ms
8,348 KB
testcase_07 AC 4 ms
8,188 KB
testcase_08 AC 3 ms
8,288 KB
testcase_09 AC 4 ms
8,200 KB
testcase_10 AC 4 ms
8,152 KB
testcase_11 AC 187 ms
35,584 KB
testcase_12 AC 166 ms
25,828 KB
testcase_13 AC 233 ms
34,292 KB
testcase_14 AC 88 ms
18,896 KB
testcase_15 AC 68 ms
16,696 KB
testcase_16 AC 257 ms
36,144 KB
testcase_17 AC 332 ms
41,732 KB
testcase_18 AC 328 ms
41,744 KB
testcase_19 AC 318 ms
39,108 KB
testcase_20 AC 145 ms
22,832 KB
testcase_21 AC 152 ms
23,272 KB
testcase_22 AC 54 ms
14,764 KB
testcase_23 AC 44 ms
13,428 KB
testcase_24 AC 130 ms
32,948 KB
testcase_25 AC 318 ms
45,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef pair<int64_t, int64_t> P;

vector<P> edges[200000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        edges[a].push_back({b, c});
        edges[b].push_back({a, c});
        edges[a+N].push_back({b+N, c});
        edges[b+N].push_back({a+N, c});
        edges[a].push_back({b+N, 0});
        edges[b].push_back({a+N, 0});
    }

    int64_t dist[200000];
    for(int i=0; i<2*N; i++) dist[i] = 1e18;
    dist[0] = dist[N] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, 0});
    while(que.size()){
        auto p = que.top(); que.pop();
        int64_t d = p.first;
        int i = p.second;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }

    for(int i=0; i<N; i++){
        int64_t ans = dist[i] + dist[i+N];
        printf("%lld\n", ans);
    }
    return 0;
}
0