結果

問題 No.807 umg tours
ユーザー chocopuuchocopuu
提出日時 2019-03-22 22:15:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,034 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 178,628 KB
実行使用メモリ 33,280 KB
最終ジャッジ日時 2023-10-19 09:36:14
合計ジャッジ時間 5,998 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
7,652 KB
testcase_07 WA -
testcase_08 AC 4 ms
7,584 KB
testcase_09 AC 4 ms
7,588 KB
testcase_10 AC 4 ms
7,600 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 118 ms
28,568 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define FOR(i,n) for(int i = 0;i<n;i++)
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
typedef vector<vint>vvint;

int N,M;
struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};
vector <edge> tree[100010];
ll dist[100010];
int dist2[100010];

void dijkstra(int s){
    priority_queue<pint,vpint,greater<pint>> que;
    fill(dist,dist+N,INF);
    dist[s]=0;
    que.push(pint(0,s));

    while(!que.empty()){
        pint p=que.top();
        que.pop();
        int v=p.se;
        if(dist[v]<p.fi)continue;
        rep(i,0,tree[v].size()){
            edge e=tree[v][i];
            if(dist[e.to]>dist[v]+e.cost){
                dist[e.to]=dist[v]+e.cost;
                que.push(pint(dist[e.to],e.to));
            }
        }
    }
}


signed main() {
    IOS();
    cin>>N>>M;
    vpint v(M);
    rep(i,0,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        if(a>b)swap(a,b);
        v[i]={a,b};
        tree[a].pb({b,c});
        tree[b].pb({a,c});
    }
    dijkstra(0);
    rep(i,0,100010)dist2[i]=INF;
    rep(i,0,M){
        chmin(dist2[i],dist[i]);
        chmin(dist2[v[i].se],dist[v[i].fi]);
    }
    
    vint ans(N);
    rep(i,0,N)ans[i]=dist[i];
    rep(i,0,N){
        tree[0].pb({i,dist2[i]});
        tree[i].pb({0,dist2[i]});
    }
    dijkstra(0);
    rep(i,0,N){
        cout<<ans[i]+dist[i]<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}
0