結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-03-22 23:30:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 2,395 ms
コンパイル使用メモリ 214,272 KB
実行使用メモリ 43,580 KB
最終ジャッジ日時 2023-10-19 10:52:20
合計ジャッジ時間 9,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 3 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 3 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 359 ms
32,416 KB
testcase_12 AC 354 ms
24,508 KB
testcase_13 AC 484 ms
33,280 KB
testcase_14 AC 201 ms
16,188 KB
testcase_15 AC 158 ms
13,736 KB
testcase_16 AC 513 ms
35,204 KB
testcase_17 AC 640 ms
42,680 KB
testcase_18 AC 626 ms
42,804 KB
testcase_19 AC 619 ms
39,340 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 332 ms
33,080 KB
testcase_25 AC 654 ms
43,580 KB
権限があれば一括ダウンロードができます

ソースコード

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);
	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