結果

問題 No.807 umg tours
ユーザー kappybarkappybar
提出日時 2020-04-21 13:59:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 657 ms / 4,000 ms
コード長 1,453 bytes
コンパイル時間 2,977 ms
コンパイル使用メモリ 178,648 KB
実行使用メモリ 46,676 KB
最終ジャッジ日時 2023-08-15 12:47:27
合計ジャッジ時間 10,939 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,476 KB
testcase_01 AC 6 ms
7,720 KB
testcase_02 AC 5 ms
8,152 KB
testcase_03 AC 6 ms
7,924 KB
testcase_04 AC 6 ms
7,948 KB
testcase_05 AC 5 ms
7,564 KB
testcase_06 AC 6 ms
8,032 KB
testcase_07 AC 5 ms
7,868 KB
testcase_08 AC 3 ms
7,416 KB
testcase_09 AC 5 ms
7,392 KB
testcase_10 AC 5 ms
7,940 KB
testcase_11 AC 479 ms
42,604 KB
testcase_12 AC 334 ms
28,168 KB
testcase_13 AC 520 ms
40,504 KB
testcase_14 AC 195 ms
22,076 KB
testcase_15 AC 152 ms
18,028 KB
testcase_16 AC 569 ms
38,772 KB
testcase_17 AC 657 ms
46,032 KB
testcase_18 AC 642 ms
45,456 KB
testcase_19 AC 647 ms
45,380 KB
testcase_20 AC 280 ms
23,164 KB
testcase_21 AC 291 ms
23,776 KB
testcase_22 AC 119 ms
14,816 KB
testcase_23 AC 89 ms
13,172 KB
testcase_24 AC 286 ms
35,316 KB
testcase_25 AC 651 ms
46,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,int> ;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 100005,m = 200005;
vector<vector<P>> graph(2*n,vector<P>());


vector<ll> dijkstra(ll start){
    vector<ll> shortest(2*n+10);
    vector<bool> visited(2*n+10,false);
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(make_pair(0,start));
    while (!pq.empty()){
        P now = pq.top();
        pq.pop();
        ll cost;int node;
        tie(cost,node) = now;
        if(visited[node]){
            continue;
        }else{
            shortest[node] = cost;
            visited[node] = true;
            for(P next:graph[node]){
                ll next_cost;int next_node;
                tie(next_cost,next_node) = next;
                pq.push(make_pair(cost+next_cost,next_node));
            }
        }
    }
    return shortest;
}


int main(){
    cin >> n >> m;
    rep(i,m){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        --a;--b;
        graph[a].push_back(P(c,b));
        graph[a].push_back(P(0,b+n));
        graph[b].push_back(P(c,a));
        graph[b].push_back(P(0,a+n));
        graph[a+n].push_back(P(c,b+n));
        graph[b+n].push_back(P(c,a+n));
    }

    vector<ll> dis = dijkstra(0);

    rep(i,n){
        if(i==0) cout << 0 << '\n';
        else cout << dis[i] + dis[i+n] << '\n';
    }

    return 0;
}
0