結果

問題 No.160 最短経路のうち辞書順最小
ユーザー itezpaceitezpace
提出日時 2016-11-15 07:22:14
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 957 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 73,748 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-04 13:50:11
合計ジャッジ時間 9,936 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
int N,S,M,G;
vector<vector<int>> vg;
vector<int> vc;
vector<vector<int>> vp;

void exp(int a,int b,vector<int> vh){
  for(int i=0;i<N;++i){
    if(a!=i && vg[a][i]){
      int b2=b+vg[a][i];
      if(b2>vc[i]) continue;
      if(b2<vc[i] && i==G){
        vp.clear();
      }
      vc[i]=b2;
      vector<int> vh2=vh;
      vh2.push_back(i);
      if(i==G){
        vp.push_back(vh2);
      } else {
        exp(i,b2,vh2);
      }
    }
  }
}

int main(){
  cin>>N>>M>>S>>G;
  vg.resize(N);
  for(int i=0;i<N;++i){
    vg[i].resize(N);
  }
  int a,b,c;
  for(int i=0;i<M;++i){
    cin>>a>>b>>c;
    vg[a][b]=c;
    vg[b][a]=c;
  }
  vc.resize(N);
  for(int i=0;i<N;++i){
    vc[i]=INT_MAX;
  }
  vc[S]=0;
  vector<int> vh;
  exp(S,0,vh);
  sort(vp.begin(),vp.end());
  cout<<S;
  for(int i=0;i<vp[0].size();++i){
    cout<<" "<<vp[0][i];
  }
  cout<<endl;
}
0