結果

問題 No.160 最短経路のうち辞書順最小
ユーザー たこしたこし
提出日時 2015-06-08 17:45:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,673 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 93,856 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 19:54:01
合計ジャッジ時間 2,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF_MIN 100000000
#define INF 1145141919
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-10
#define PI acos(-1)
#define LL long long

using namespace std;

#define MAX_N 201
#define MAX_M 40001

typedef pair<int, int> P; //distance, next

int N, M, S, G;

int dp[MAX_N][MAX_N];
int dpOrigin[MAX_N][MAX_N];

int main(){

  cin >> N >> M >> S >> G;

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      dp[i][j] = dpOrigin[i][j] = INF_MIN;
    }
    dp[i][i] = dpOrigin[i][i] = 0;
  }

  for(int i = 0; i < M; i++){
    int a, b, c;
    cin >> a >> b >> c;
    dpOrigin[a][b] = dpOrigin[b][a] = dp[a][b] = dp[b][a] = c;
  }

  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
	dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }

  vector<int> ans;

  int pos = S;

  while(true){
    ans.push_back(pos);
    if(pos == G)
      break;
    for(int i = 0; i < N; i++){
      if(pos == i)
	continue;
      if(dpOrigin[pos][i] + dp[i][G] == dp[pos][G]){
	pos = i;
	break;
      }
    }
  }

  for(int i = 0; i < ans.size(); i++){
    cout << ans[i];
    if(i < ans.size() - 1)
      cout << " ";
  }
  cout << endl;

  return 0;

}
0