結果

問題 No.807 umg tours
ユーザー furafura
提出日時 2020-05-30 04:52:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 566 ms / 4,000 ms
コード長 1,426 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 211,076 KB
実行使用メモリ 71,340 KB
最終ジャッジ日時 2023-08-15 12:53:28
合計ジャッジ時間 9,389 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 287 ms
52,312 KB
testcase_12 AC 275 ms
40,972 KB
testcase_13 AC 412 ms
55,952 KB
testcase_14 AC 141 ms
26,072 KB
testcase_15 AC 103 ms
22,276 KB
testcase_16 AC 427 ms
63,496 KB
testcase_17 AC 552 ms
70,368 KB
testcase_18 AC 549 ms
69,332 KB
testcase_19 AC 530 ms
67,392 KB
testcase_20 AC 237 ms
39,552 KB
testcase_21 AC 256 ms
40,752 KB
testcase_22 AC 88 ms
19,408 KB
testcase_23 AC 62 ms
15,924 KB
testcase_24 AC 219 ms
55,808 KB
testcase_25 AC 566 ms
71,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
	G[v].emplace_back(u,wt);
}

template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
}

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	const T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

const long long INF=1LL<<61;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	weighted_graph<lint> G(2*n),H(2*n);
	rep(i,m){
		int u,v;
		lint c; scanf("%d%d%lld",&u,&v,&c); u--; v--;
		add_edge(G,u,v,c);
		add_edge(G,u+n,v+n,c);
		add_directed_edge(G,u,v+n,0LL);
		add_edge(H,u,v,c);
		add_edge(H,u+n,v+n,c);
		add_directed_edge(H,v,u+n,0LL);
	}

	auto d1=Dijkstra(G,0);
	auto d2=Dijkstra(H,0);
	rep(u,n) printf("%lld\n",min({d1[u]+d2[u],d1[u]+d2[u+n],d1[u+n]+d2[u]}));

	return 0;
}
0