結果

問題 No.807 umg tours
ユーザー a0171610a0171610
提出日時 2020-05-18 21:38:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 391 ms / 4,000 ms
コード長 1,091 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 186,968 KB
実行使用メモリ 24,776 KB
最終ジャッジ日時 2023-08-15 12:51:02
合計ジャッジ時間 7,385 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 235 ms
15,964 KB
testcase_12 AC 208 ms
14,864 KB
testcase_13 AC 289 ms
18,184 KB
testcase_14 AC 114 ms
9,888 KB
testcase_15 AC 84 ms
8,596 KB
testcase_16 AC 305 ms
18,864 KB
testcase_17 AC 382 ms
24,776 KB
testcase_18 AC 378 ms
24,608 KB
testcase_19 AC 364 ms
21,332 KB
testcase_20 AC 187 ms
12,708 KB
testcase_21 AC 188 ms
13,056 KB
testcase_22 AC 75 ms
7,364 KB
testcase_23 AC 56 ms
6,396 KB
testcase_24 AC 172 ms
21,368 KB
testcase_25 AC 391 ms
24,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint n, m;
typedef tuple<lint, lint, lint> P;
struct edge{lint to, cost;};
vector<vector<edge> > G;
vector<vector<lint> > dist;
const lint INF= 1e18;

void dij(int start){
	priority_queue<P, vector<P>, greater<P> > que;
	dist[0][0] = 0; dist[1][0] = 0;
	que.push(P(0, 0, 0));
	while(que.size()){
		P p = que.top(); que.pop();
		int d = get<0>(p), u = get<1>(p), flag = get<2>(p);
		if(dist[flag][u] < d) continue;
		for(auto e : G[u]){
			if(dist[flag][e.to] > dist[flag][u] + e.cost){
				dist[flag][e.to] = dist[flag][u] + e.cost;
				que.push(P(dist[flag][e.to], e.to, flag));
			}
			if(flag == 0 && dist[1][e.to] > dist[0][u]){
				dist[1][e.to] = dist[0][u];
				que.push(P(dist[1][e.to], e.to, 1));
			}
		} 
	}
}
signed main(){
	cin >> n >> m;
	G.resize(n);
	dist.resize(2, vector<lint> (n, INF));
	for(int i = 0; i < m; i++){
		lint a, b, c; cin >> a >> b >> c; --a; --b;
		G[a].push_back(edge{b, c}); G[b].push_back(edge{a, c});
	}
	dij(0);
	for(int i = 0; i < n; i++) cout << dist[0][i] + dist[1][i] << '\n';
}
0