結果

問題 No.807 umg tours
ユーザー 👑 kmjpkmjp
提出日時 2019-03-22 21:36:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 4,000 ms
コード長 1,493 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 179,176 KB
実行使用メモリ 17,548 KB
最終ジャッジ日時 2024-05-02 23:17:16
合計ジャッジ時間 5,909 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 4 ms
5,888 KB
testcase_02 AC 4 ms
5,888 KB
testcase_03 AC 3 ms
5,888 KB
testcase_04 AC 4 ms
5,760 KB
testcase_05 AC 3 ms
5,760 KB
testcase_06 AC 4 ms
5,760 KB
testcase_07 AC 3 ms
5,760 KB
testcase_08 AC 3 ms
5,888 KB
testcase_09 AC 4 ms
5,888 KB
testcase_10 AC 4 ms
5,760 KB
testcase_11 AC 132 ms
12,844 KB
testcase_12 AC 168 ms
12,040 KB
testcase_13 AC 200 ms
13,796 KB
testcase_14 AC 97 ms
9,396 KB
testcase_15 AC 98 ms
8,436 KB
testcase_16 AC 235 ms
14,264 KB
testcase_17 AC 298 ms
17,156 KB
testcase_18 AC 281 ms
17,548 KB
testcase_19 AC 275 ms
15,332 KB
testcase_20 AC 189 ms
11,136 KB
testcase_21 AC 187 ms
11,392 KB
testcase_22 AC 81 ms
8,280 KB
testcase_23 AC 68 ms
7,680 KB
testcase_24 AC 212 ms
15,588 KB
testcase_25 AC 285 ms
17,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<pair<int,int>> E[101010];
ll dp[101010][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
		E[y-1].push_back({x-1,r});
	}
	FOR(i,N) dp[i][0]=dp[i][1]=1LL<<60;
	priority_queue<pair<ll,int>> Q;
	dp[0][0]=dp[0][1]=0;
	Q.push({0,0});
	Q.push({0,100000});
	while(Q.size()) {
		int cur=Q.top().second%100000;
		int step=Q.top().second/100000;
		ll co=-Q.top().first;
		Q.pop();
		if(dp[cur][step]!=co) continue;
		FORR(e,E[cur]) {
			if(dp[e.first][step]>co+e.second) {
				dp[e.first][step]=co+e.second;
				Q.push({-dp[e.first][step],e.first+step*100000});
			}
			if(step==0 && dp[e.first][1]>co) {
				dp[e.first][1]=co;
				Q.push({-dp[e.first][1],e.first+100000});
			}
		}
	}
	FOR(i,N) cout<<dp[i][0]+min(dp[i][0],dp[i][1])<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0