結果

問題 No.160 最短経路のうち辞書順最小
ユーザー 沙耶花沙耶花
提出日時 2021-11-02 22:32:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,133 bytes
コンパイル時間 5,021 ms
コンパイル使用メモリ 266,832 KB
実行使用メモリ 7,364 KB
最終ジャッジ日時 2024-04-20 09:17:38
合計ジャッジ時間 6,414 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 32 ms
7,364 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){	
	
	int N,M,S,G;
	cin>>N>>M>>S>>G;
	
	vector<int> a(M),b(M),c(M);
	
	vector<vector<int>> E(N);
	
	rep(i,M){
		cin>>a[i]>>b[i]>>c[i];
		E[a[i]].push_back(i);
		E[b[i]].push_back(i);
	}
	vector<int> t = {};
	vector<pair<int,vector<int>>> dis(N,make_pair(Inf,t));
	
	priority_queue<pair<pair<int,vector<int>>,int>,vector<pair<pair<int,vector<int>>,int>>,greater<pair<pair<int,vector<int>>,int>>> Q;
	t.push_back(G);
	dis[G] = make_pair(0,t);
	Q.emplace(make_pair(0,t), G);
	
	while(Q.size()>0){
		auto p = Q.top().first;
		int u = Q.top().second;
		Q.pop();
		if(dis[u]!=p)continue;
		rep(i,E[u].size()){
			int v = u ^ a[E[u][i]] ^ b[E[u][i]];
			auto pp = p;
			pp.second.insert(pp.second.begin(),v);
			pp.first += c[E[u][i]];
			if(dis[v]>pp){
				dis[v] = pp;
				Q.emplace(pp,v);
			}
		}
		
	}
	
	auto ans = dis[S].second;
	rep(i,ans.size()){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
	
}
0