結果

問題 No.807 umg tours
ユーザー addeight2
提出日時 2019-03-23 10:49:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 339 ms / 4,000 ms
コード長 1,089 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 168,612 KB
実行使用メモリ 24,340 KB
最終ジャッジ日時 2024-11-23 19:16:48
合計ジャッジ時間 6,873 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5,INF=1e18;
ll N,M;
struct edge{
	ll to,cst;
};
vector<edge> G[MAX_N];
ll dst[MAX_N][2];
struct st{
	ll v,f;
};
bool operator<(const st &a,const st &b){
	return a.v<b.v;
}
typedef pair<ll,st> P;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M;
	REP(i,M){
		ll a,b,c;
		cin>>a>>b>>c;
		a--;
		b--;
		G[a].push_back((edge){b,c});
		G[b].push_back((edge){a,c});
	}
	REP(v,N)REP(f,2)dst[v][f]=INF;
	dst[0][0]=0;
	priority_queue<P,vector<P>,greater<P> > pque;
	pque.push(P(0,(st){0,0}));
	while(!pque.empty()){
		P p=pque.top();
		pque.pop();
		st s=p.second;
		if(dst[s.v][s.f]<p.first)continue;
		for(auto e:G[s.v]){
			REP(i,2){
				if(s.f==1 && i==1)continue;
				ll cst=(i==0 ? e.cst : 0),f2=(i==0 ? s.f : 1);
				if(dst[e.to][f2]>p.first+cst){
					dst[e.to][f2]=p.first+cst;
					pque.push(P(dst[e.to][f2],(st){e.to,f2}));
				}
			}
		}
	}
	cout<<0<<endl;
	REP(i,N-1){
		cout<<dst[i+1][0]+dst[i+1][1]<<endl;
	}
}
0