結果

問題 No.807 umg tours
ユーザー milanis48663220milanis48663220
提出日時 2019-10-27 16:42:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 627 ms / 4,000 ms
コード長 1,289 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 69,120 KB
実行使用メモリ 41,960 KB
最終ジャッジ日時 2024-05-03 00:02:48
合計ジャッジ時間 8,228 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,064 KB
testcase_01 AC 6 ms
8,192 KB
testcase_02 AC 6 ms
8,192 KB
testcase_03 AC 5 ms
8,192 KB
testcase_04 AC 6 ms
8,064 KB
testcase_05 AC 5 ms
8,192 KB
testcase_06 AC 6 ms
8,320 KB
testcase_07 AC 6 ms
8,320 KB
testcase_08 AC 5 ms
8,192 KB
testcase_09 AC 6 ms
8,192 KB
testcase_10 AC 6 ms
8,064 KB
testcase_11 AC 350 ms
35,580 KB
testcase_12 AC 358 ms
25,964 KB
testcase_13 AC 477 ms
34,452 KB
testcase_14 AC 195 ms
18,992 KB
testcase_15 AC 156 ms
16,640 KB
testcase_16 AC 505 ms
36,368 KB
testcase_17 AC 618 ms
40,860 KB
testcase_18 AC 615 ms
40,972 KB
testcase_19 AC 607 ms
39,176 KB
testcase_20 AC 352 ms
22,912 KB
testcase_21 AC 374 ms
23,296 KB
testcase_22 AC 149 ms
14,848 KB
testcase_23 AC 113 ms
13,440 KB
testcase_24 AC 337 ms
32,684 KB
testcase_25 AC 627 ms
41,960 KB
権限があれば一括ダウンロードができます

ソースコード

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