結果

問題 No.807 umg tours
ユーザー polylogK
提出日時 2019-03-22 21:40:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,305 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 184,596 KB
実行使用メモリ 32,128 KB
最終ジャッジ日時 2024-11-23 18:53:26
合計ジャッジ時間 10,561 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

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