結果

問題 No.807 umg tours
ユーザー milanis48663220milanis48663220
提出日時 2019-10-27 16:42:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,289 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 69,296 KB
実行使用メモリ 42,116 KB
最終ジャッジ日時 2023-10-12 22:53:43
合計ジャッジ時間 11,289 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,220 KB
testcase_01 AC 4 ms
8,140 KB
testcase_02 AC 4 ms
8,152 KB
testcase_03 AC 4 ms
8,128 KB
testcase_04 AC 4 ms
8,088 KB
testcase_05 AC 4 ms
8,196 KB
testcase_06 AC 4 ms
8,252 KB
testcase_07 AC 4 ms
8,124 KB
testcase_08 AC 3 ms
8,076 KB
testcase_09 AC 3 ms
8,228 KB
testcase_10 AC 4 ms
8,064 KB
testcase_11 AC 343 ms
35,300 KB
testcase_12 AC 343 ms
25,880 KB
testcase_13 AC 471 ms
34,168 KB
testcase_14 AC 196 ms
19,048 KB
testcase_15 AC 151 ms
16,908 KB
testcase_16 AC 481 ms
36,240 KB
testcase_17 AC 613 ms
41,800 KB
testcase_18 AC 605 ms
40,920 KB
testcase_19 AC 604 ms
39,028 KB
testcase_20 WA -
testcase_21 AC 370 ms
23,132 KB
testcase_22 WA -
testcase_23 AC 112 ms
13,316 KB
testcase_24 AC 325 ms
33,004 KB
testcase_25 AC 601 ms
42,116 KB
権限があれば一括ダウンロードができます

ソースコード

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