結果

問題 No.160 最短経路のうち辞書順最小
ユーザー itezpaceitezpace
提出日時 2016-08-18 07:27:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,023 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 65,756 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-25 08:43:25
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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>
using namespace std;

vector<vector<int>> v;
int n,m,s,g,a,b,c;
vector<int> vi;
int x;

void calc(int d,int e,int f,vector<int> vi2){
  int d2,e2,f2;
  vector<int> vi3;
  vi3=vi2;
  vi3[d]=f;
  if(d==g){
    if(e<x){
      x=e;
      vi=vi3;
    }
  } else {
    for(int i=0; i<n; ++i){
      if(v[d][i]!=0 && vi3[i]==0){
        d2=i;
        e2=e;
        f2=f;
        e2+=v[d][d2];
        f2++;
        calc(d2,e2,f2,vi3);
      }
    }
  }
}

int main(){
  cin>>n>>m>>s>>g;
  v.resize(n);
  for(int i=0; i<n; ++i){
    v[i].resize(n);
    for(int j=0; j<n; ++j){
      v[i].push_back(0);
    }
  }
  for(int i=0; i<m; ++i){
    cin>>a>>b>>c;
    v[a][b]=c;
    v[b][a]=c;
  }
  x=INT_MAX;
  for(int i=0; i<n; ++i){
    vi.push_back(0);
  }
  calc(s,0,1,vi);
  for(int i=1; i<=n; ++i){
    for(int j=0; j<n; ++j){
      if(i==1 && vi[j]==i){
        cout<<j;
      } else if(i>1 && vi[j]==i){
        cout<<" "<<j;
      }
    }
  }
  cout<<endl;
  return 0;
}
0