結果

問題 No.807 umg tours
ユーザー Tlapesium
提出日時 2019-03-22 23:34:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 733 ms / 4,000 ms
コード長 1,068 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 205,372 KB
最終ジャッジ日時 2025-01-07 00:07:03
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct edge {
	ll to;
	ll cost;
};
typedef pair<ll, ll> P;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<edge>> G(N * 2, vector<edge>());
	vector<ll> d(N * 2, INF_LL);
	for (int i = 0; i < M; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
		G[a].push_back({ b + N,0 });
		G[b].push_back({ a + N,0 });
		G[a + N].push_back({ b + N,c });
		G[b + N].push_back({ a + N,c });
	}
	priority_queue<P, vector<P>, greater<P>> q;
	d[0] = 0;
	q.push(P{ 0,0 });

	while (!q.empty()) {
		P p = q.top(); q.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P{ d[e.to] , e.to });
			}
		}
	}

	for (int i = 0; i < N; i++) {
		cout << min(d[i] + d[i + N], d[i] * 2) << endl;
	}
}
0