結果

問題 No.160 最短経路のうち辞書順最小
ユーザー wing3196wing3196
提出日時 2015-03-01 23:58:59
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,319 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 85,032 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 06:04:16
合計ジャッジ時間 2,532 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
using namespace std;

struct Way{
	int to,cost;
	Way(){}
	Way(int _to,int _cost){
		to=_to; cost=_cost;
	}
};

struct Data{
	int n,cost;
	Data(){}
	Data(int _n,int _cost){
		n=_n; cost=_cost;
	}
	bool operator<(const Data &a)const{
		return cost>a.cost;
	}
};

int main(){
	vector<Way> way[200];
	int N,M,S,G,A,B,C;
	cin>>N>>M>>S>>G;
	for(int i=0;i<M;i++){
		cin>>A>>B>>C;
		way[A].push_back(Way(B,C)); way[B].push_back(Way(A,C));
	}

	priority_queue<Data> pq; pq.push(Data(S,0));
	Data pq_c;
	int d[200]; fill_n((int*)d,200,INT_MAX);
	while(!pq.empty()){
		pq_c = pq.top(); pq.pop();
		if(d[pq_c.n]!=INT_MAX) continue;
		d[pq_c.n] = pq_c.cost;
		for(int i=0;i<way[pq_c.n].size();i++){
			pq.push(Data(way[pq_c.n][i].to,pq_c.cost+way[pq_c.n][i].cost));
		}
	}
	
	stack<int> s;
	int n=G;
	s.push(n);
	while(n!=S){
		int next=INT_MAX;
		for(int i=0;i<way[n].size();i++){
			if(d[n]-way[n][i].cost == d[way[n][i].to]){
				next = min(next,way[n][i].to);
			}
		}
		n = next;
		s.push(n);
	}

	printf("%d",s.top()); s.pop();
	while(!s.empty()){
		printf(" %d",s.top()); s.pop();
	}puts("");
    return 0;
}
0