結果

問題 No.160 最短経路のうち辞書順最小
ユーザー IL_mstaIL_msta
提出日時 2015-08-09 20:40:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,814 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 95,504 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-25 07:37:07
合計ジャッジ時間 2,607 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
const int Vmax = 200;

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	int N,M,start,goal;
	cin>>N>>M>>start>>goal;
	int vvc[Vmax][Vmax];
	rep(i,200)rep(j,200)vvc[i][j] = -1;
	int a,b,c;
	rep(i,M){
		cin>>a>>b>>c;
		vvc[a][b] = c;
		vvc[b][a] = c;
	}

	//(cost,pos)
	priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> q;
	vector<int> itq;
	bool use[Vmax];
	PII dist[Vmax];//cost,prev
	rep(i,N){
		use[i] = false;
		dist[i] = PII( -1,-1);
	}

	vector<int> vec(3);
	vec[0] = 0;
	vec[1] = start;
	vec[2] = start;
	q.push( vec );
	while( !q.empty() ){
		itq = q.top();q.pop();
		if( use[itq[1] ] == true ) continue;
		use[itq[1] ] = true;
		dist[itq[1] ] = PII( itq[0],itq[2]);
		for(int i=0; i<N ;++i){//頂点数
			if( use[i] == true || vvc[itq[1]][i] < 0 ) continue;
			vec[0] = itq[0] + vvc[itq[1]][i];
			vec[1] = i;
			vec[2] = itq[1];
			q.push( vec );
		}
	}

	int path[Vmax];
	int pathCount = 0;
	int pathPrev = goal;
	while( pathPrev != start )
	{
		path[pathCount] = pathPrev;
		++pathCount;;

		pathPrev = dist[pathPrev].second;
	}
	path[pathCount] = start;
	while(pathCount > 0){
		cout << path[pathCount] << " ";
		--pathCount;
	}
	cout << path[pathCount] << endl;

	
	return 0;
}
0