結果

問題 No.807 umg tours
ユーザー ogingingoginging
提出日時 2019-03-22 23:02:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 658 ms / 4,000 ms
コード長 1,588 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 167,144 KB
実行使用メモリ 60,928 KB
最終ジャッジ日時 2024-05-02 23:31:06
合計ジャッジ時間 10,050 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
26,880 KB
testcase_01 AC 11 ms
27,008 KB
testcase_02 AC 12 ms
27,008 KB
testcase_03 AC 13 ms
27,008 KB
testcase_04 AC 12 ms
27,008 KB
testcase_05 AC 11 ms
27,008 KB
testcase_06 AC 11 ms
26,880 KB
testcase_07 AC 12 ms
27,008 KB
testcase_08 AC 12 ms
26,880 KB
testcase_09 AC 12 ms
26,880 KB
testcase_10 AC 10 ms
26,880 KB
testcase_11 AC 372 ms
54,464 KB
testcase_12 AC 364 ms
45,012 KB
testcase_13 AC 500 ms
53,448 KB
testcase_14 AC 205 ms
38,048 KB
testcase_15 AC 167 ms
35,584 KB
testcase_16 AC 515 ms
55,312 KB
testcase_17 AC 645 ms
59,656 KB
testcase_18 AC 637 ms
59,684 KB
testcase_19 AC 648 ms
58,256 KB
testcase_20 AC 369 ms
41,728 KB
testcase_21 AC 390 ms
42,368 KB
testcase_22 AC 163 ms
33,664 KB
testcase_23 AC 126 ms
32,128 KB
testcase_24 AC 349 ms
51,432 KB
testcase_25 AC 658 ms
60,928 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