結果

問題 No.160 最短経路のうち辞書順最小
ユーザー mizunomidorimizunomidori
提出日時 2016-07-04 02:34:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,436 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 74,760 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 21:45:49
合計ジャッジ時間 1,840 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 14 ms
6,940 KB
testcase_06 AC 16 ms
6,940 KB
testcase_07 AC 11 ms
6,944 KB
testcase_08 AC 10 ms
6,940 KB
testcase_09 AC 10 ms
6,944 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 10 ms
6,940 KB
testcase_12 AC 10 ms
6,940 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 10 ms
6,940 KB
testcase_18 AC 9 ms
6,940 KB
testcase_19 AC 10 ms
6,940 KB
testcase_20 AC 10 ms
6,940 KB
testcase_21 AC 10 ms
6,944 KB
testcase_22 AC 10 ms
6,940 KB
testcase_23 AC 10 ms
6,944 KB
testcase_24 AC 10 ms
6,944 KB
testcase_25 AC 10 ms
6,940 KB
testcase_26 AC 9 ms
6,944 KB
testcase_27 AC 9 ms
6,944 KB
testcase_28 AC 20 ms
6,944 KB
testcase_29 AC 9 ms
6,944 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