結果

問題 No.160 最短経路のうち辞書順最小
ユーザー koba-e964koba-e964
提出日時 2015-04-30 18:48:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,348 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 87,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 04:41:23
合計ジャッジ時間 3,033 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int N = 210;

int dist[N][N];

int orig[N][N];

int n;
void trace(int s, int g) {
  if (s == g) {
    cout << g << endl;
    return;
  }
  REP(i, 0, n) {
    if (dist[s][g] == dist[i][g] + orig[s][i]) {
      cout << s << " ";
      trace(i, g);
      return;
    }
  }
  assert(0);
}

int main(void){
  const int inf = 0x3fffff;
  int m, s, g;
  cin >> n >> m >> s >> g;
  REP(i,0,n) {
    REP(j,0,n) {
      dist[i][j] = orig[i][j] = inf;
    }
    dist[i][i] = 0;
  }
  REP(i, 0, m) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a][b] = orig[a][b] = c;
    dist[b][a] = orig[b][a] = c;
  }
  REP(k, 0, n) {
    REP(i, 0, n) {
      REP(j, 0, n) {
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  trace(s, g);
}
0