結果

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

ソースコード

diff #

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

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

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