結果

問題 No.160 最短経路のうち辞書順最小
ユーザー IL_mstaIL_msta
提出日時 2015-08-10 17:52:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,583 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 89,168 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 07:55:14
合計ジャッジ時間 2,386 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 10 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 10 ms
4,376 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 9 ms
4,376 KB
testcase_26 AC 10 ms
4,380 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 13 ms
4,380 KB
testcase_29 AC 9 ms
4,376 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 d[Vmax][Vmax];
	int cost[Vmax][Vmax];
	const int INF = (int)1e8/2;

	rep(i,Vmax)rep(j,Vmax){
		d[i][j] = INF;
		cost[i][j] = INF;
	}
	rep(i,N){
		d[i][i] = 0;
		cost[i][i] = 0;
	}
	
	int a,b,c;
	rep(i,M){
		cin>>a>>b>>c;
		d[a][b] = c;
		d[b][a] = c;
		cost[a][b] = c;
		cost[b][a] = c;
	}

	rep(i,N)rep(j,N)rep(k,N){
		d[j][k] = min( d[j][k],d[j][i]+d[i][k] );
	}
	
	int now;
	now = start;
	vector<int> ans;
	ans.push_back(now);
	bool flag=true;
	while(flag)
	{
		flag = false;
		rep(i,N){
			if( now == i)continue;
			if( d[start][now]+cost[now][i]+d[i][goal] == d[start][goal] ){
				now = i;
				flag = true;
				ans.push_back(now);
				break;
			}
		}
	}
	//ans.push_back(goal);
	vector<int>::iterator it = ans.begin();
	for(;it != ans.end();++it){
		cout << *it;
		if( it+1 != ans.end() ){
			cout << " ";
		}else{
			cout << endl;
		}
	}
	return 0;
}
0