結果

問題 No.160 最短経路のうち辞書順最小
ユーザー knewknowlknewknowl
提出日時 2015-03-02 21:25:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 707 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 64,988 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 06:32:01
合計ジャッジ時間 1,975 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 12 ms
4,376 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 11 ms
4,380 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 11 ms
4,380 KB
testcase_25 AC 11 ms
4,376 KB
testcase_26 AC 11 ms
4,380 KB
testcase_27 AC 10 ms
4,376 KB
testcase_28 AC 21 ms
4,380 KB
testcase_29 AC 10 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int G[200][200];
int D[200][200];
int main(){
  int n,m,s,g;cin>>n>>m>>s>>g;
  for(int i=0;i<n;++i) for(int j=0;j<n;++j) G[i][j] = (i==j)?0:1<<25;
  while(m--){
    int a,b,c;cin>>a>>b>>c;
    G[a][b]=G[b][a]=c;
    D[a][b]=D[b][a]=c;
  }
  for(int k=0;k<n;++k) for(int i=0;i<n;++i) for(int j=0;j<n;++j) G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
  vector<int> root;root.push_back(s);
  while(true){
    for(int i=0;i<n;++i){
      if(D[s][i]&&D[s][i]+G[i][g]==G[s][g]){
	root.push_back(i);
	s=i;
	break;
      }
    }
    if(s==g) break;
  }
  for(int i=0,m=root.size();i<m;++i) cout << root[i]<<" ";
  cout << endl;
  return 0;
}
0