結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-08-10 17:52:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 1,583 bytes |
| コンパイル時間 | 702 ms |
| コンパイル使用メモリ | 89,536 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 06:32:03 |
| 合計ジャッジ時間 | 1,656 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#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;
}
IL_msta