結果

問題 No.807 umg tours
ユーザー betrue12betrue12
提出日時 2019-03-22 22:02:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 367 ms / 4,000 ms
コード長 1,165 bytes
コンパイル時間 2,410 ms
コンパイル使用メモリ 207,096 KB
実行使用メモリ 42,188 KB
最終ジャッジ日時 2024-05-02 23:23:34
合計ジャッジ時間 7,960 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,300 KB
testcase_01 AC 5 ms
8,336 KB
testcase_02 AC 4 ms
8,372 KB
testcase_03 AC 4 ms
8,432 KB
testcase_04 AC 5 ms
8,320 KB
testcase_05 AC 4 ms
8,316 KB
testcase_06 AC 5 ms
8,428 KB
testcase_07 AC 4 ms
8,428 KB
testcase_08 AC 5 ms
8,320 KB
testcase_09 AC 5 ms
8,320 KB
testcase_10 AC 5 ms
8,364 KB
testcase_11 AC 197 ms
35,716 KB
testcase_12 AC 194 ms
26,264 KB
testcase_13 AC 271 ms
34,708 KB
testcase_14 AC 98 ms
19,176 KB
testcase_15 AC 76 ms
16,860 KB
testcase_16 AC 282 ms
36,432 KB
testcase_17 AC 367 ms
41,024 KB
testcase_18 AC 360 ms
41,312 KB
testcase_19 AC 347 ms
39,496 KB
testcase_20 AC 173 ms
22,912 KB
testcase_21 AC 169 ms
23,680 KB
testcase_22 AC 64 ms
14,996 KB
testcase_23 AC 50 ms
13,644 KB
testcase_24 AC 137 ms
33,068 KB
testcase_25 AC 358 ms
42,188 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