結果

問題 No.807 umg tours
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-16 15:48:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,926 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 81,208 KB
実行使用メモリ 18,428 KB
最終ジャッジ日時 2023-09-14 15:17:27
合計ジャッジ時間 5,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,652 KB
testcase_01 AC 6 ms
7,736 KB
testcase_02 AC 6 ms
7,588 KB
testcase_03 AC 5 ms
7,680 KB
testcase_04 AC 6 ms
7,568 KB
testcase_05 AC 6 ms
7,788 KB
testcase_06 AC 5 ms
7,616 KB
testcase_07 AC 5 ms
7,820 KB
testcase_08 AC 5 ms
7,808 KB
testcase_09 AC 5 ms
7,664 KB
testcase_10 AC 6 ms
7,700 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 AC 134 ms
12,768 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 323 ms
18,208 KB
testcase_21 AC 328 ms
18,428 KB
testcase_22 AC 135 ms
12,436 KB
testcase_23 AC 105 ms
11,760 KB
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
int N,M,used[100010] = {};
P parent[100010];
vector<vector<P>> v(100010),tree(100010);
ll dp[100010][2] = {},inf = 1e18;

void dfs(int n,int m){
    for(auto x:tree[n]){
        if(x.second!=m){
            dfs(x.second,n);
            dp[n][1] = min(dp[n][1],dp[x.second][1]+x.first);
        }
    }
}

int main(){
    cin >> N >> M;
    assert(2<=N && N<=100000);
    assert(N-1<=M && M<=min(100000,N*(N-1)/2));
    int a,b; ll c;
    for(int i=0;i<M;i++){
        cin >> a >> b >> c;
        assert(1<=a && a<=N && 1<=b && b<=N && 1<=c && c<=1000000000);
        v[a].push_back(P(c,b));
        v[b].push_back(P(c,a));
    }
    for(int i=2;i<=N;i++){
        dp[i][0] = inf;
        dp[i][1] = inf;
    }
    priority_queue<P,vector<P>,greater<P>> Q;
    priority_queue<P> Q2;
    
    Q.push(P(0,1));
    int cnt = 0;
    while(!Q.empty()){
        P p = Q.top(); Q.pop();
        int n = p.second;
        used[n] = 1;
        if(dp[n][0]<p.first) continue;
        Q2.push(p);
        for(auto x:v[n]){
           if(dp[x.second][0]>p.first+x.first){
                dp[x.second][0] = p.first+x.first;
                parent[x.second] = P(x.first,n);
                Q.push(P(dp[x.second][0],x.second));
            }
            if(used[x.second]!=1) dp[x.second][1] = min(min(dp[x.second][1],dp[n][1]+x.first),p.first);
        }
    }
/*    for(int i=2;i<=N;i++){
        tree[parent[i].second].push_back(P(parent[i].first,i));
    }
    dfs(1,0);
*/   
    while(!Q2.empty()){
        P p = Q2.top(); Q2.pop();
        int n = p.second;
        for(auto x:v[n]){
            dp[x.second][1] = min(dp[x.second][1],dp[n][1]+x.first);
        }
    }
    for(int i=1;i<=N;i++){
        assert(dp[i][0]!=inf && dp[i][1]!=inf);
        cout << dp[i][0]+dp[i][1] << endl;
    }
}
0