結果

問題 No.807 umg tours
ユーザー ogingingoginging
提出日時 2019-03-22 23:02:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 620 ms / 4,000 ms
コード長 1,588 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 152,920 KB
実行使用メモリ 63,088 KB
最終ジャッジ日時 2023-08-15 12:05:38
合計ジャッジ時間 9,406 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
27,916 KB
testcase_01 AC 12 ms
27,936 KB
testcase_02 AC 12 ms
28,060 KB
testcase_03 AC 12 ms
28,104 KB
testcase_04 AC 12 ms
27,908 KB
testcase_05 AC 12 ms
27,980 KB
testcase_06 AC 12 ms
28,068 KB
testcase_07 AC 12 ms
28,096 KB
testcase_08 AC 12 ms
27,940 KB
testcase_09 AC 12 ms
27,968 KB
testcase_10 AC 11 ms
27,936 KB
testcase_11 AC 350 ms
54,824 KB
testcase_12 AC 344 ms
44,716 KB
testcase_13 AC 474 ms
55,068 KB
testcase_14 AC 202 ms
38,208 KB
testcase_15 AC 159 ms
36,080 KB
testcase_16 AC 495 ms
56,908 KB
testcase_17 AC 620 ms
61,724 KB
testcase_18 AC 611 ms
62,592 KB
testcase_19 AC 598 ms
59,292 KB
testcase_20 AC 346 ms
43,248 KB
testcase_21 AC 356 ms
43,840 KB
testcase_22 AC 152 ms
33,876 KB
testcase_23 AC 119 ms
32,636 KB
testcase_24 AC 332 ms
54,500 KB
testcase_25 AC 609 ms
63,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;


#define INF 10000000000000000
#define MAX_V 1000000

struct edge{ll to,cost;};
ll d[MAX_V];
ll V;
vector<edge> G[MAX_V];

edge makeedge(ll t,ll c){
    edge e;
    e.to=t;
    e.cost=c;
    return e;
}

void addedge(ll s,ll t,ll c){
    G[s].push_back(makeedge(t,c));
    G[t].push_back(makeedge(s,c)); //双方向
}

void addedge2(ll s,ll t,ll c){
    G[s].push_back(makeedge(t,c));
    //G[t].push_back(makeedge(s,c)); //双方向
}

void dijkstra(ll s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s)); 

    while(!que.empty()){
        P p=que.top(); que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        for(ll i=0;i<G[v].size();i++){
            edge &e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}



int main(){
    ll i,j;
    ll n,m;
    cin>>n>>m;
    V=2*n;
    ll a,b,c;
    for(i=0;i<m;i++){
        cin>>a>>b>>c;
        a--;
        b--;
        addedge(2*a,2*b,c);
        addedge(2*a+1,2*b+1,c);
        addedge2(2*a,2*b+1,0);
        addedge2(2*b,2*a+1,0);
    }
    dijkstra(0);

    cout<<0<<endl;
    for(i=1;i<n;i++){
        cout<<d[i*2]+d[i*2+1]<<endl;
    }
    
    return 0;
}
0