結果

問題 No.807 umg tours
ユーザー ldsybldsyb
提出日時 2019-03-22 23:37:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,083 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 182,960 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 10:54:24
合計ジャッジ時間 8,877 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int64_t n, m;
	cin >> n >> m;
	vector<vector<pair<int64_t, int>>> g(n);
	for (int i = 0; i < m; i++)
	{
		int64_t a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].push_back({c, b});
		g[b].push_back({c, a});
	}
	vector<vector<int64_t>> dist(n, vector<int64_t>(2, (1LL << 60)));
	dist[0][0] = 0;
	priority_queue<pair<int64_t, pair<int, int>>> pq;
	pq.push({dist[0][0], {0, 0}});
	while (!pq.empty())
	{
		int64_t score = pq.top().first;
		int x = pq.top().second.first;
		int y = pq.top().second.second;
		pq.pop();
		if (dist[x][y] < score)
		{
			continue;
		}
		for (auto &p : g[x])
		{
			int64_t cost = p.first;
			int to = p.second;
			if (dist[x][y] + cost < dist[to][y])
			{
				dist[to][y] = dist[x][y] + cost;
				pq.push({dist[to][y], {to, y}});
			}
			if (y == 0)
			{
				if (dist[x][y] < dist[to][1])
				{
					dist[to][1] = dist[x][y];
					pq.push({dist[to][1], {to, 1}});
				}
			}
		}
	}
	cout << 0 << endl;
	for (int i = 1; i < n; i++)
	{
		cout << dist[i][0] + dist[i][1] << endl;
	}
	return 0;
}
0