結果

問題 No.807 umg tours
コンテスト
ユーザー toppo57
提出日時 2026-10-25 12:13:54
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 152 ms / 4,000 ms
+ 10µs
コード長 1,415 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,399 ms
コンパイル使用メモリ 197,488 KB
実行使用メモリ 22,028 KB
最終ジャッジ日時 2026-10-25 12:14:03
合計ジャッジ時間 8,052 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int, ll>>>;
using pli = pair<ll, int>;

const ll INF = 1LL<<50;

int N, M;

Graph G(100010);
ll D[200010];

void Dijkstra(int src){
    fill(&D[0], &D[0]+200010, INF);
    D[src]=0; D[src+N]=0;
    priority_queue<pli, vector<pli>, greater<pli>> Q;
    Q.push({0, src});
    Q.push({0, src+N});

    while(! Q.empty()){
        auto [dist, cur] = Q.top();
        Q.pop();

        if(dist>D[cur]) continue;
        if (cur>N){
            for (auto [dst, d]: G[cur-N]){
                if (dist+d<D[dst+N]){
                    Q.push({D[dst+N]=dist+d, dst+N});
                }
            }
        }
        else{
            for (auto [dst, d]: G[cur]){
                if (dist+d<D[dst]){
                    Q.push({D[dst]=dist+d, dst});
                }
                if (dist<D[dst+N]){
                    Q.push({D[dst+N]=dist, dst+N});
                }
            }
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    scanf("%d %d", &N, &M);

    for (int i=0;i<M;i++){
        int A, B; ll C;
        scanf("%d %d %lld", &A, &B, &C);
        G[A].push_back({B, C});
        G[B].push_back({A, C});
    }
    Dijkstra(1);
    for (int i=1;i<=N;i++){
        printf("%lld\n", D[i]+D[i+N]);
    }
    return 0;
}
0