結果

問題 No.807 umg tours
ユーザー aa
提出日時 2019-03-22 23:33:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 932 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 177,736 KB
実行使用メモリ 19,212 KB
最終ジャッジ日時 2023-10-19 10:53:05
合計ジャッジ時間 7,738 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using P = pair<long, int>;

struct edge {int to; long c;};

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<long> dist(n, 1e18);
	dist[0] = 0;
	vector<edge> g[n];
	while(m--)
	{
		int a, b;
		long c;
		cin >> a >> b >> c;
		a--, b--;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	priority_queue<P, vector<P>, greater<P>> q;
	q.push({0, 0});
	while(!q.empty())
	{
		auto p = q.top();
		q.pop();
		int v = p.second;
		long c = p.first;
		if (dist[v] < c) continue;
		for (auto np : g[v])
		{
			int nv = np.to;
			long nc = np.c + dist[v];
			if (dist[nv] > nc)
			{
				dist[nv] = nc;
				q.push({nc, nv});
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		long ans = dist[i], plus = dist[i];
		for (auto e : g[i])
		{
			plus = min(plus, dist[e.to]);
		}
		ans += plus;
		cout << ans << endl;
	}
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0