結果

問題 No.807 umg tours
ユーザー TlapesiumTlapesium
提出日時 2019-03-22 22:35:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,750 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 215,888 KB
実行使用メモリ 21,780 KB
最終ジャッジ日時 2023-10-19 09:50:19
合計ジャッジ時間 12,966 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 3 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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), d2(N, INF);
	priority_queue<P, vector<P>, greater<P>> q;
	d1[0] = 0; d2[0] = 0;
	q.push(P{ 0,{0,false} });
	while (!q.empty()) {
		P p = q.top(); q.pop();
		ll v = p.second.first;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (p.second.second == false) {
				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 (d1[e.to] > p.first) {
					d1[e.to] = p.first;
					q.push(P{ d1[e.to],{ e.to, true } });
				}
			}
			if (d1[e.to] > d1[v] + e.cost) {
				d1[e.to] = d1[v] + e.cost;
				q.push(P{ d1[e.to], { e.to, p.second.second } });

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

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