結果

問題 No.807 umg tours
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-16 18:07:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 415 ms / 4,000 ms
コード長 1,080 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 77,652 KB
実行使用メモリ 42,132 KB
最終ジャッジ日時 2024-05-02 23:11:41
合計ジャッジ時間 6,168 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,064 KB
testcase_01 AC 6 ms
8,064 KB
testcase_02 AC 6 ms
8,192 KB
testcase_03 AC 6 ms
8,192 KB
testcase_04 AC 7 ms
8,064 KB
testcase_05 AC 5 ms
8,064 KB
testcase_06 AC 6 ms
8,320 KB
testcase_07 AC 5 ms
8,192 KB
testcase_08 AC 6 ms
8,064 KB
testcase_09 AC 6 ms
8,064 KB
testcase_10 AC 6 ms
8,064 KB
testcase_11 AC 218 ms
35,756 KB
testcase_12 AC 209 ms
26,112 KB
testcase_13 AC 298 ms
34,604 KB
testcase_14 AC 112 ms
19,172 KB
testcase_15 AC 84 ms
16,840 KB
testcase_16 AC 309 ms
36,492 KB
testcase_17 AC 395 ms
40,848 KB
testcase_18 AC 415 ms
41,008 KB
testcase_19 AC 391 ms
39,336 KB
testcase_20 AC 188 ms
23,040 KB
testcase_21 AC 201 ms
23,552 KB
testcase_22 AC 77 ms
14,848 KB
testcase_23 AC 57 ms
13,312 KB
testcase_24 AC 144 ms
32,940 KB
testcase_25 AC 400 ms
42,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
int N,M;
vector<vector<P>> v(200010);
ll dp[200010] = {},inf = 1e18;

int main(){
    scanf("%d %d",&N,&M);
    int a,b; ll c;
    for(int i=0;i<M;i++){
        scanf("%d %d %d",&a,&b,&c);
        v[a].push_back(P(c,b));
        v[a].push_back(P(0,b+N));
        v[b].push_back(P(c,a));
        v[b].push_back(P(0,a+N));
        v[a+N].push_back(P(c,b+N));
        v[b+N].push_back(P(c,a+N));
    }
    for(int i=2;i<=2*N;i++){
        if(i!=N+1) dp[i] = inf;
    }
    priority_queue<P,vector<P>,greater<P>> Q;
    Q.push(P(0,1));
    int cnt = 0;
    while(!Q.empty()){
        P p = Q.top(); Q.pop();
        int n = p.second;
        if(dp[n]<p.first) continue;
        for(auto x:v[n]){
           if(dp[x.second]>p.first+x.first){
                dp[x.second] = p.first+x.first;
                Q.push(P(dp[x.second],x.second));
            }
        }
    }
    for(int i=1;i<=N;i++){
        printf("%lld\n",dp[i]+dp[i+N]);
    }
}
0