結果

問題 No.160 最短経路のうち辞書順最小
ユーザー TAISA_TAISA_
提出日時 2018-06-22 00:24:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,136 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 155,260 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 07:46:25
合計ジャッジ時間 3,306 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
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 AC 4 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-3;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int d[210];
struct edge{int to,cost;};
vector<edge> G[210];
int p[210];
int main(){
	int n,m,s,g;cin>>n>>m>>s>>g;
	for(int i=0;i<m;i++){
		int a,b,c;cin>>a>>b>>c;
		G[a].push_back({b,c});
		G[b].push_back({a,c});
	}
	priority_queue<P,vector<P>,greater<P>> q;
	q.push(P(0,s));
	fill(d,d+n,INF);
	fill(p,p+n,-1);
	d[s]=0;
	while(!q.empty()){
		P pp=q.top();q.pop();
		int v=pp.second;
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(d[e.to]==d[v]+e.cost){
				p[e.to]=min(v,p[e.to]);
			}
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				p[e.to]=v;
				q.push(P(d[e.to],e.to));
			}
		}
	}
	vector<int> ans;
	for(int i=g;i!=s;i=p[i])ans.push_back(i);
	ans.push_back(s);
	reverse(all(ans));
	for(int i=0;i<ans.size();i++){
		cout<<ans[i];
		if(i!=ans.size()-1){
			cout<<" ";
		}
	}
	cout<<endl;
    return 0;
}
0