結果

問題 No.807 umg tours
ユーザー square1001square1001
提出日時 2019-03-22 21:51:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,312 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 79,988 KB
実行使用メモリ 41,064 KB
最終ジャッジ日時 2023-08-15 11:55:43
合計ジャッジ時間 10,436 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 201 ms
32,088 KB
testcase_12 AC 188 ms
24,240 KB
testcase_13 AC 270 ms
32,976 KB
testcase_14 AC 96 ms
15,796 KB
testcase_15 AC 67 ms
13,600 KB
testcase_16 AC 278 ms
34,996 KB
testcase_17 AC 365 ms
40,940 KB
testcase_18 AC 359 ms
41,064 KB
testcase_19 AC 343 ms
38,912 KB
testcase_20 AC 162 ms
22,704 KB
testcase_21 AC 166 ms
23,276 KB
testcase_22 AC 60 ms
11,936 KB
testcase_23 AC 43 ms
10,004 KB
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{ A + 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