結果

問題 No.807 umg tours
ユーザー milanis48663220
提出日時 2019-10-27 16:42:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,289 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 69,032 KB
実行使用メモリ 41,960 KB
最終ジャッジ日時 2024-09-14 21:04:19
合計ジャッジ時間 9,532 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF = 1e+10;

typedef pair<int, ll> P;

struct edge{
    int to;
    ll cost;
};

void dijkstra(int s, int num_v, vector<edge> G[], ll d[]){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+num_v, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<edge> G[200000];
ll dist[200000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back((edge){b, c});
        G[a+N].push_back((edge){b+N, c});
        G[a].push_back((edge){b+N, 0});
        G[b].push_back((edge){a, c});
        G[b+N].push_back((edge){a+N, c});
        G[b].push_back((edge){a+N, 0});
    }
    dijkstra(0, N*2, G, dist);
    cout << 0 << endl;
    for(int i = 1; i < N; i++){
        cout << dist[i]+dist[i+N] << endl;
    }
}
0