結果

問題 No.807 umg tours
ユーザー square1001square1001
提出日時 2019-03-22 21:49:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 80,160 KB
実行使用メモリ 42,568 KB
最終ジャッジ日時 2023-10-19 07:48:44
合計ジャッジ時間 10,562 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 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 <queue>
#include <vector>
#include <iostream>
using namespace std;
const long long inf = 1LL << 61;
struct edge {
	int to; long long cost;
};
struct state {
	int pos; long long cost;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost > s2.cost;
}
vector<long long> shortest_path(int src, vector<vector<edge> > &G) {
	int N = G.size();
	vector<long long> dist(N, inf);
	dist[src] = 0;
	priority_queue<state> que; que.push(state{ src, 0 });
	while (!que.empty()) {
		int u = que.top().pos; que.pop();
		for (edge e : G[u]) {
			if (dist[e.to] > dist[u] + e.cost) {
				dist[e.to] = dist[u] + e.cost;
				que.push(state{ e.to, dist[e.to] });
			}
		}
	}
	return dist;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<edge> > G(2 * N);
	for (int i = 0; i < M; ++i) {
		int A, B, C;
		cin >> A >> B >> C; --A, --B;
		G[A].push_back(edge{ B, C });
		G[A + N].push_back(edge{ B + N, C });
		G[A].push_back(edge{ B + N, 0 });
		G[B].push_back(edge{ A, C });
		G[B + N].push_back(edge{ A + N, C });
		G[B].push_back(edge{ B + N, 0 });
	}
	vector<long long> d = shortest_path(0, G);
	for (int i = 0; i < N; ++i) {
		long long ans = inf;
		ans = min(ans, d[i] * 2);
		ans = min(ans, d[i] + d[i + N]);
		cout << ans << '\n';
	}
	return 0;
}
0