結果

問題 No.807 umg tours
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-16 17:50:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 980 ms / 4,000 ms
コード長 1,799 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 51,196 KB
最終ジャッジ日時 2024-05-02 23:11:18
合計ジャッジ時間 11,347 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,936 KB
testcase_01 AC 6 ms
7,936 KB
testcase_02 AC 6 ms
8,064 KB
testcase_03 AC 6 ms
8,064 KB
testcase_04 AC 6 ms
8,064 KB
testcase_05 AC 6 ms
7,936 KB
testcase_06 AC 7 ms
8,064 KB
testcase_07 AC 6 ms
8,064 KB
testcase_08 AC 6 ms
7,936 KB
testcase_09 AC 6 ms
7,936 KB
testcase_10 AC 5 ms
7,936 KB
testcase_11 AC 583 ms
42,384 KB
testcase_12 AC 507 ms
31,172 KB
testcase_13 AC 729 ms
41,876 KB
testcase_14 AC 281 ms
22,228 KB
testcase_15 AC 227 ms
19,456 KB
testcase_16 AC 798 ms
44,364 KB
testcase_17 AC 936 ms
49,864 KB
testcase_18 AC 980 ms
50,132 KB
testcase_19 AC 932 ms
48,296 KB
testcase_20 AC 444 ms
27,392 KB
testcase_21 AC 457 ms
28,032 KB
testcase_22 AC 185 ms
16,768 KB
testcase_23 AC 137 ms
14,848 KB
testcase_24 AC 437 ms
39,852 KB
testcase_25 AC 946 ms
51,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cassert>
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(){
    cin >> N >> M;
    assert(2<=N && N<=100000);
    assert(N-1<=M && M<=min(200000,N*(N-1)/2));
    int a,b; ll c;
    set<pair<int,int>> s;
    for(int i=0;i<M;i++){
        cin >> a >> b >> c;
        if(a>b) swap(a,b);
        assert(s.count({a,b})==0);
        assert(1<=a && a<=N && 1<=b && b<=N && 1<=c && c<=1000000000);
        assert(a!=b);
        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));
        s.insert({a,b});
    }
    for(int i=2;i<=2*N;i++){
        if(i!=N+1) dp[i] = inf;
    }
    priority_queue<P,vector<P>,greater<P>> Q,Q2;
    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));
            }
        }
    }
/*    Q2.push(P(0,1));
    while(!Q2.empty()){
        P p = Q2.top(); Q2.pop();
        int n = p.second;
        if(dp[n][1]<p.first) continue;
        for(auto x:v[n]){
            if(dp[x.second][1]>min(dp[n][1]+x.first,dp[n][0])){
                dp[x.second][1] = min(dp[n][1]+x.first,dp[n][0]);
                Q2.push(P(dp[x.second][1],x.second));
            }
        }
    }
*/    for(int i=1;i<=N;i++){
        assert(dp[i]!=inf && dp[i+N]!=inf);
        cout << dp[i]+dp[i+N] << endl;
    }
}
0