結果

問題 No.807 umg tours
コンテスト
ユーザー betrue12
提出日時 2019-03-22 22:02:45
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 227 ms / 4,000 ms
コード長 1,165 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,236 ms
コンパイル使用メモリ 217,428 KB
実行使用メモリ 42,580 KB
最終ジャッジ日時 2026-06-07 08:43:03
合計ジャッジ時間 4,858 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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