結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-03-22 23:36:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 480 ms / 4,000 ms
コード長 1,442 bytes
コンパイル時間 2,530 ms
コンパイル使用メモリ 214,100 KB
実行使用メモリ 26,752 KB
最終ジャッジ日時 2024-05-02 23:34:29
合計ジャッジ時間 8,230 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 272 ms
16,008 KB
testcase_12 AC 262 ms
16,216 KB
testcase_13 AC 354 ms
19,584 KB
testcase_14 AC 140 ms
10,896 KB
testcase_15 AC 124 ms
9,700 KB
testcase_16 AC 384 ms
21,768 KB
testcase_17 AC 444 ms
23,128 KB
testcase_18 AC 447 ms
24,200 KB
testcase_19 AC 480 ms
26,752 KB
testcase_20 AC 320 ms
16,844 KB
testcase_21 AC 309 ms
16,536 KB
testcase_22 AC 121 ms
9,280 KB
testcase_23 AC 95 ms
8,284 KB
testcase_24 AC 272 ms
19,836 KB
testcase_25 AC 463 ms
24,520 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;
};
// d v f
typedef pair<ll, pair<ll, bool>> P;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<edge>> G(N, vector<edge>());
	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 });
	}
	vector<ll> d1(N, INF_LL), d2(N, INF_LL), d3(N, INF_LL);
	priority_queue<P, vector<P>, greater<P>> q, q_;
	d1[0] = 0; d2[0] = 0, d3[0] = 0;

	q.push(P{ 0,{0,false} });

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

	for (int i = 0; i < N; i++) {
		cout << d3[i] + d1[i] << endl;
	}
}
0