結果

問題 No.807 umg tours
ユーザー polylogKpolylogK
提出日時 2019-03-22 21:40:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,305 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 180,460 KB
実行使用メモリ 26,800 KB
最終ジャッジ日時 2023-08-15 11:52:40
合計ジャッジ時間 11,143 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 131 ms
15,452 KB
testcase_12 AC 124 ms
15,568 KB
testcase_13 AC 171 ms
18,648 KB
testcase_14 AC 71 ms
10,276 KB
testcase_15 AC 51 ms
8,880 KB
testcase_16 AC 174 ms
19,568 KB
testcase_17 AC 259 ms
24,836 KB
testcase_18 AC 247 ms
25,192 KB
testcase_19 AC 217 ms
22,392 KB
testcase_20 AC 109 ms
15,776 KB
testcase_21 AC 118 ms
16,260 KB
testcase_22 AC 48 ms
9,000 KB
testcase_23 AC 34 ms
7,596 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