結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-10-31 21:49:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 412 ms / 4,000 ms
コード長 1,337 bytes
コンパイル時間 3,183 ms
コンパイル使用メモリ 228,348 KB
実行使用メモリ 44,732 KB
最終ジャッジ日時 2023-08-15 12:36:06
合計ジャッジ時間 8,442 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 186 ms
32,424 KB
testcase_12 AC 228 ms
25,156 KB
testcase_13 AC 297 ms
34,372 KB
testcase_14 AC 115 ms
16,796 KB
testcase_15 AC 91 ms
13,648 KB
testcase_16 AC 311 ms
36,088 KB
testcase_17 AC 402 ms
42,872 KB
testcase_18 AC 412 ms
43,248 KB
testcase_19 AC 386 ms
40,496 KB
testcase_20 AC 229 ms
23,268 KB
testcase_21 AC 247 ms
24,128 KB
testcase_22 AC 94 ms
12,220 KB
testcase_23 AC 74 ms
10,364 KB
testcase_24 AC 222 ms
33,884 KB
testcase_25 AC 394 ms
44,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int 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;

void dijkstra(int s, vector<vector<edge>>& g, vector<ll> &d) {
	priority_queue <P, vector<P>, greater<P>> q;
	d = vector<ll>(g.size(), INF_LL);
	d[s] = 0;
	q.push({ 0, s });

	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({ d[e.to], e.to });
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<vector<edge>> g(N*2);
	for (int i = 0; i < M; i++) {
		int 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 });
	}
	vector<ll> d(N * 2);
	dijkstra(0, g, d);
	for (int i = 0; i < N; i++) {
		cout << min(d[i] + d[i + N], d[i] * 2) << endl;
	}
}
0