結果

問題 No.160 最短経路のうち辞書順最小
ユーザー wing3196wing3196
提出日時 2015-03-02 03:09:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,271 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 84,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 06:20:45
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 5 ms
4,380 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,376 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 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,380 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,376 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,prev;
	Data(){}
	Data(int _n,int _cost,int _prev){
		n=_n; cost=_cost; prev=_prev;
	}
	bool operator<(const Data &a)const{
		if(cost==a.cost) return prev>a.prev;
		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,-1));
	Data pq_c;
	bool used[200]={};
	int prev[200];
	while(!pq.empty()){
		pq_c = pq.top(); pq.pop();
		if(used[pq_c.n]==true) continue;
		used[pq_c.n] = true;
		prev[pq_c.n] = pq_c.prev;
		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,pq_c.n));
		}
	}
	
	stack<int> s;
	int n=G;
	s.push(n);
	while(n!=S){
		n = prev[n];
		s.push(n);
	}

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