結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,064 KB
testcase_01 AC 3 ms
8,064 KB
testcase_02 AC 3 ms
8,200 KB
testcase_03 AC 3 ms
8,200 KB
testcase_04 AC 4 ms
8,120 KB
testcase_05 AC 4 ms
8,056 KB
testcase_06 AC 3 ms
8,172 KB
testcase_07 AC 3 ms
8,192 KB
testcase_08 AC 2 ms
8,056 KB
testcase_09 AC 4 ms
8,048 KB
testcase_10 AC 3 ms
8,064 KB
testcase_11 AC 151 ms
35,880 KB
testcase_12 AC 144 ms
26,036 KB
testcase_13 AC 204 ms
34,728 KB
testcase_14 AC 82 ms
19,296 KB
testcase_15 AC 59 ms
16,836 KB
testcase_16 AC 219 ms
36,620 KB
testcase_17 AC 283 ms
40,976 KB
testcase_18 AC 284 ms
41,132 KB
testcase_19 AC 275 ms
39,336 KB
testcase_20 AC 129 ms
23,008 KB
testcase_21 AC 145 ms
23,544 KB
testcase_22 AC 52 ms
14,924 KB
testcase_23 AC 39 ms
13,440 KB
testcase_24 AC 126 ms
32,780 KB
testcase_25 AC 298 ms
42,260 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("%ld\n",dp[i]+dp[i+N]);
    }
}
0