結果

問題 No.160 最短経路のうち辞書順最小
ユーザー itezpaceitezpace
提出日時 2016-11-15 07:22:14
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 957 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 73,252 KB
実行使用メモリ 818,036 KB
最終ジャッジ日時 2024-11-26 01:39:54
合計ジャッジ時間 113,878 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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