結果

問題 No.807 umg tours
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-08-29 13:20:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 616 ms / 4,000 ms
コード長 1,271 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 180,016 KB
実行使用メモリ 42,868 KB
最終ジャッジ日時 2023-08-15 12:57:58
合計ジャッジ時間 9,897 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 331 ms
32,196 KB
testcase_12 AC 337 ms
24,232 KB
testcase_13 AC 458 ms
33,100 KB
testcase_14 AC 187 ms
15,968 KB
testcase_15 AC 145 ms
13,592 KB
testcase_16 AC 492 ms
34,936 KB
testcase_17 AC 612 ms
41,448 KB
testcase_18 AC 606 ms
41,304 KB
testcase_19 AC 616 ms
39,156 KB
testcase_20 AC 364 ms
22,396 KB
testcase_21 AC 365 ms
23,168 KB
testcase_22 AC 142 ms
11,828 KB
testcase_23 AC 112 ms
9,900 KB
testcase_24 AC 322 ms
32,912 KB
testcase_25 AC 612 ms
42,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const ll INF = 1000000000000000000;

//経路復元なしDijkstra法
template<class T> 
vector<T> dijkstra(int start, T INF, const vector<vector<pair<int,T>>>& Hen){
	int N = Hen.size();
	vector<T> dist(N, INF);
	vector<bool> seen(N);
	dist[start] = 0;
	priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> que;
	que.emplace(0, start);

	while(que.size()) {
		int ver = que.top().second;
		T cost = que.top().first; que.pop();
		if(seen[ver])continue;
		seen[ver] = true;
		for(auto i : Hen[ver]) {
			if(dist[i.first] > cost + i.second) {
				dist[i.first] = cost + i.second;
				que.emplace(dist[i.first], i.first);
			}
		}
	}
	return dist;
}



int n, m;
int id(int v, int p) {
	return p * n + v;
}


int main()
{
	cin >> n >> m;
	vector<vector<pair<int,ll>>> hen(n * 2);
	for(int i = 0; i < m; i++) {
		int a, b, c; cin >> a >> b >> c; a--, b--;
		for(int j = 0; j < 2; j++) {
			hen[id(a,j)].push_back({id(b,j), c});
			hen[id(b,j)].push_back({id(a,j), c});
		}
		hen[id(a,0)].push_back({id(b, 1), 0});
		hen[id(b,0)].push_back({id(a, 1), 0});	
	}
	vector<ll> dist = dijkstra(0, INF, hen);


	for(int i = 0; i < n; i++) {
		cout << dist[i] + min(dist[i+n],dist[i]) << endl;
	}

}
0