結果

問題 No.807 umg tours
ユーザー ats5515ats5515
提出日時 2019-03-22 21:28:36
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,351 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 93,068 KB
実行使用メモリ 34,820 KB
最終ジャッジ日時 2023-08-15 11:49:25
合計ジャッジ時間 13,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 238 ms
17,636 KB
testcase_12 AC 305 ms
19,456 KB
testcase_13 AC 394 ms
23,024 KB
testcase_14 AC 155 ms
12,608 KB
testcase_15 AC 118 ms
10,552 KB
testcase_16 AC 418 ms
24,684 KB
testcase_17 AC 581 ms
31,048 KB
testcase_18 AC 548 ms
30,660 KB
testcase_19 AC 517 ms
27,624 KB
testcase_20 AC 300 ms
20,408 KB
testcase_21 AC 319 ms
21,060 KB
testcase_22 AC 118 ms
11,332 KB
testcase_23 AC 90 ms
9,204 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<int> > g(N);
	vector<vector<int> > l(N);
	int res = 0;
	int a, b, c;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		l[a].push_back(c);
		l[b].push_back(c);
	}


	priority_queue < pair<int, pair<int, int> > > pq;
	int INF = (int)1 << 60;
	vector<vector<int> > dist(N, vector<int>(2, INF));

	dist[0][0] = 0;
	dist[0][1] = 0;
	pq.emplace(-dist[0][0], make_pair(0, 0));
	pq.emplace(-dist[0][1], make_pair(0, 1));

	while (pq.size() > 0) {
		a = pq.top().second.first;
		b = pq.top().second.second;
		pq.pop();

		int d = dist[a][b];

		for (int i = 0; i < g[a].size(); i++) {
			if (dist[g[a][i]][b] > d + l[a][i]) {
				dist[g[a][i]][b] = d + l[a][i];
				pq.emplace(-dist[g[a][i]][b], make_pair(g[a][i], b));
			}
			if (b == 0) {
				if (dist[g[a][i]][1] > d) {
					dist[g[a][i]][1] = d;
					pq.emplace(-dist[g[a][i]][1], make_pair(g[a][i], 1));
				}
			}
		}


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