結果

問題 No.807 umg tours
ユーザー startcppstartcpp
提出日時 2019-03-22 22:20:30
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,221 bytes
コンパイル時間 2,232 ms
コンパイル使用メモリ 79,012 KB
実行使用メモリ 30,056 KB
最終ジャッジ日時 2023-08-15 12:03:34
合計ジャッジ時間 12,321 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,532 KB
testcase_01 AC 3 ms
8,052 KB
testcase_02 AC 4 ms
8,112 KB
testcase_03 AC 4 ms
8,264 KB
testcase_04 AC 4 ms
8,204 KB
testcase_05 AC 3 ms
8,380 KB
testcase_06 AC 4 ms
8,180 KB
testcase_07 AC 4 ms
8,096 KB
testcase_08 AC 4 ms
8,028 KB
testcase_09 AC 3 ms
8,032 KB
testcase_10 AC 3 ms
8,164 KB
testcase_11 AC 285 ms
20,628 KB
testcase_12 AC 291 ms
18,832 KB
testcase_13 AC 408 ms
22,696 KB
testcase_14 AC 164 ms
14,180 KB
testcase_15 AC 147 ms
12,672 KB
testcase_16 AC 403 ms
23,576 KB
testcase_17 AC 515 ms
27,972 KB
testcase_18 AC 498 ms
27,628 KB
testcase_19 AC 490 ms
25,112 KB
testcase_20 AC 295 ms
17,232 KB
testcase_21 AC 293 ms
17,440 KB
testcase_22 AC 122 ms
12,056 KB
testcase_23 AC 98 ms
11,204 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

typedef tuple<int, int, int> T;
priority_queue<T, vector<T>, greater<T>> que;

int INF = 1e+15;
int n, m;
vector<int> et[100000];
vector<int> ec[100000];
int dist[100000][2];

signed main() {
	int i, j;
	
	cin >> n >> m;
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c; a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
		ec[a].push_back(c);
		ec[b].push_back(c);
	}
	
	rep(i, n) rep(j, 2) dist[i][j] = INF;
	que.push(T(0, 0, 0));
	dist[0][0] = 0;
	
	while (!que.empty()) {
		T now = que.top(); que.pop();
		int cst = get<0>(now);
		int pos = get<1>(now);
		int kai = get<2>(now);
		rep(i, et[pos].size()) {
			int npos = et[pos][i];
			if (kai == 0) {
				if (dist[npos][1] > cst) {
					que.push(T(cst, npos, 1));
					dist[npos][1] = cst;
				}
			}
			if (dist[npos][kai] > cst + ec[pos][i]) {
				que.push(T(cst + ec[pos][i], npos, kai));
				dist[npos][kai] = cst + ec[pos][i];
			}
		}
	}
	
	rep(i, n) {
		int x = 2 * dist[i][0];
		int y = dist[i][0] + dist[i][1];
		cout << min(x, y) << endl;
	}
	return 0;
}
0