結果

問題 No.160 最短経路のうち辞書順最小
ユーザー k_zt0215k_zt0215
提出日時 2016-07-20 15:10:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,435 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 75,168 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 17:03:07
合計ジャッジ時間 1,957 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

#define N_MAX 200
#define M_MAX (N_MAX * (N_MAX-1) / 2)
#define C_MAX 10000
#define INF (N_MAX * C_MAX)

using namespace std;

int main(void)
{
    int N, M, S, G, cost[N_MAX][N_MAX], d[N_MAX][N_MAX];
    cin >> N >> M >> S >> G;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) {
                cost[i][j] = d[i][j] = 0;
            } else {
                cost[i][j] = d[i][j] = INF;
            }
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        cost[a][b] = d[a][b] = c;
        cost[b][a] = d[b][a] = c;
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int x = S;
    int l = d[S][G];
    while (x != G) {
        printf("%d ", x);
        for (int i = 0; i < N; i++) {
            if (i != x && cost[x][i] + d[i][G] == l) {
                x = i;
                l = d[i][G];
                break;
            }
        }
    }
    printf("%d\n", G);
    return 0;
}
0