結果

問題 No.160 最短経路のうち辞書順最小
ユーザー mkawa2mkawa2
提出日時 2020-01-24 15:22:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,088 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 11,600 KB
最終ジャッジ日時 2023-10-12 04:09:06
合計ジャッジ時間 2,320 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,772 KB
testcase_01 AC 16 ms
7,832 KB
testcase_02 AC 16 ms
7,864 KB
testcase_03 AC 16 ms
7,768 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# 同じ距離のときにルートの辞書順が小さい方を選べばいいので
# キーの2番目にルートを文字列でいれておいてワーシャルフロイド
def main():
    inf = 10 ** 9
    n, m, s, g = MI()
    edge = [LI() for _ in range(m)]
    node = [(inf, "")] * n
    node[s] = (0, str(s))
    update = True
    while update:
        update = False
        for u, v, c in edge:
            if node[u] > node[v]: u, v = v, u
            du, ru = node[u]
            dv, rv = node[v]
            if dv > du + c or (dv == du + c and rv > ru + str(v)):
                node[v] = (du + c, ru + str(v))
                update = True

    path = list(node[g][1])
    print(*path)

main()
0