結果

問題 No.160 最短経路のうち辞書順最小
ユーザー なおなお
提出日時 2015-03-02 01:42:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 773 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 145,220 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 06:18:49
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int g[222][222],r[222][222];

int main(){
    do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);

    int N,M,S,G;
    cin >> N >> M >> S >> G;

    const int INF = 1<<28;
    REP(i,N)REP(j,N) g[i][j] = INF;
    REP(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g[a][b] = g[b][a] = c;
        r[a][b] = r[b][a] = c;
    }
    REP(i,N) g[i][i] = 0;

    REP(k,N)REP(i,N)REP(j,N)
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

    int v = S;
    cout << S;
    while(v != G){
        REP(i,N) if(v != i && r[v][i] == g[v][i] && g[v][G] == g[v][i]+g[i][G]){ v = i; break; }
        cout << " " << v;
    }
    cout << endl;

    return 0;
}
0