結果

問題 No.807 umg tours
ユーザー kappybarkappybar
提出日時 2020-04-21 13:52:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,472 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 177,972 KB
実行使用メモリ 37,136 KB
最終ジャッジ日時 2024-04-16 22:42:15
合計ジャッジ時間 13,966 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 6 ms
7,936 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

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,ll> ;
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(n);
    vector<bool> visited(n,false);
    priority_queue<pair<ll,ll>,vector<pair<ll ,ll>>,greater<pair<ll,ll>>> pq;
    pq.push(make_pair(0,start));
    while (!pq.empty()){
        pair<ll,ll> now = pq.top();
        pq.pop();
        ll cost,node;
        tie(cost,node) = now;
        if(visited[node]){
            continue;
        }else{
            shortest[node] = cost;
            visited[node] = true;
            for(pair<ll,ll> next:graph[node]){
                ll next_cost,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){
        ll a,b,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