結果

問題 No.807 umg tours
ユーザー yurujirouyurujirou
提出日時 2023-04-03 20:50:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 782 ms / 4,000 ms
コード長 1,295 bytes
コンパイル時間 4,317 ms
コンパイル使用メモリ 266,676 KB
実行使用メモリ 39,700 KB
最終ジャッジ日時 2023-10-25 06:54:17
合計ジャッジ時間 13,459 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
22,076 KB
testcase_01 AC 8 ms
22,076 KB
testcase_02 AC 8 ms
22,120 KB
testcase_03 AC 8 ms
22,116 KB
testcase_04 AC 7 ms
22,076 KB
testcase_05 AC 8 ms
22,080 KB
testcase_06 AC 9 ms
22,160 KB
testcase_07 AC 8 ms
22,112 KB
testcase_08 AC 7 ms
22,052 KB
testcase_09 AC 8 ms
22,056 KB
testcase_10 AC 8 ms
22,072 KB
testcase_11 AC 541 ms
33,684 KB
testcase_12 AC 428 ms
31,552 KB
testcase_13 AC 597 ms
36,460 KB
testcase_14 AC 245 ms
28,428 KB
testcase_15 AC 196 ms
25,560 KB
testcase_16 AC 652 ms
34,796 KB
testcase_17 AC 782 ms
39,248 KB
testcase_18 AC 781 ms
39,256 KB
testcase_19 AC 775 ms
39,292 KB
testcase_20 AC 396 ms
28,500 KB
testcase_21 AC 420 ms
28,616 KB
testcase_22 AC 166 ms
26,444 KB
testcase_23 AC 126 ms
23,752 KB
testcase_24 AC 408 ms
37,348 KB
testcase_25 AC 780 ms
39,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define LREP(i, n) for(LL i = 0; i < (LL)n; i++)
#define RREP(i, n) for(int i = (int)n-1; i >= 0; i--)
#define V(T) vector<T>

#define P pair<int, int>
#define LP pair<LL, LL>
#define T3 tuple<LL, LL, LL>
#define T4 tuple<LL, LL, LL, LL>
#define INF 1000000007
#define SIZE 500100
#define MOD 998244353
typedef long long LL;

LL N, M;
LL A[SIZE], B[SIZE], C[SIZE];
V(int) E[SIZE];
LL dist[SIZE];

int main() {
	cin >> N >> M;
	REP(i, M) {
		cin >> A[i] >> B[i] >> C[i];
		A[i]--; B[i]--;
		E[A[i]].push_back(i);
		E[B[i]].push_back(i);
	}

	REP(i, 2 * N) dist[i] = 1e18;
	priority_queue<LP, V(LP), greater<LP>> que;
	que.push(LP(0, 0)); // have a ticket
	que.push(LP(0, N));
	while (que.size()) {
		LP p = que.top(); que.pop();
		LL d = p.first, u = p.second;
		if (dist[u] <= d) continue;
		dist[u] = d;
		for (auto i : E[u % N]) {
			LL v = A[i], cost = C[i];
			if (v % N == u % N) v = B[i];
			if (u < N) {
				que.push(LP(d + cost, v));
				que.push(LP(d, v + N));
			}
			else {
				que.push(LP(d + cost, v + N));
			}
		}
	}

	REP(i, N) {
		cout << dist[i] + dist[i + N] << endl;
	}
}
0