結果

問題 No.807 umg tours
ユーザー polylogKpolylogK
提出日時 2019-03-22 21:40:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,305 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 183,888 KB
実行使用メモリ 29,924 KB
最終ジャッジ日時 2024-05-02 23:18:25
合計ジャッジ時間 10,340 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 126 ms
15,680 KB
testcase_12 AC 122 ms
15,828 KB
testcase_13 AC 163 ms
18,832 KB
testcase_14 AC 69 ms
10,624 KB
testcase_15 AC 51 ms
9,088 KB
testcase_16 AC 176 ms
19,600 KB
testcase_17 AC 250 ms
24,708 KB
testcase_18 AC 244 ms
24,612 KB
testcase_19 AC 227 ms
22,736 KB
testcase_20 AC 118 ms
15,868 KB
testcase_21 AC 119 ms
16,512 KB
testcase_22 AC 44 ms
9,088 KB
testcase_23 AC 33 ms
7,936 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

std::vector<std::vector<std::pair<int, i64>>> g;

std::vector<std::vector<i64>> solve(int s = 0) {
	using P = std::pair<i64, std::pair<int, int>>;
	std::vector<std::vector<i64>> min_cost(g.size(), std::vector<i64>(2, 1LL << 60));
	std::priority_queue<P, std::vector<P>, std::greater<P>> qu;
	min_cost[s][0] = min_cost[s][1] = 0; qu.push({0, {0, 0}});
	while(!qu.empty()) {
		auto p = qu.top(); qu.pop();
		
		for(auto e: g[p.second.first]) {
			if(p.first + e.second < min_cost[e.first][p.second.second]) {
				min_cost[e.first][p.second.second] = p.first + e.second;
				qu.push({p.first + e.second, {e.first, p.second.second}});
			}
			
			if(!p.second.second) {
				if(p.first >= min_cost[e.first][1]) continue;
				min_cost[e.first][1] = p.first;
				qu.push({p.first, {e.first, 1}});
			}
		}
	}
	return min_cost;
}

int main() {
	int n, m; scanf("%d%d", &n, &m); g.resize(n);
	for(int i = 0; i < m; i++) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		
		g[a - 1].push_back({b - 1, c});
		g[b - 1].push_back({a - 1, c});
	}
	auto min_cost = solve();
	
	for(int i = 0; i < n; i++) {
		printf("%lld\n", min_cost[i][0] + min_cost[i][1]);
	}
	return 0;
}
0