結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | mkawa2 |
提出日時 | 2020-01-24 14:58:27 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,129 bytes |
コンパイル時間 | 125 ms |
コンパイル使用メモリ | 10,872 KB |
実行使用メモリ | 16,084 KB |
最終ジャッジ日時 | 2023-10-12 04:08:41 |
合計ジャッジ時間 | 2,587 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
8,572 KB |
testcase_01 | AC | 21 ms
8,612 KB |
testcase_02 | AC | 21 ms
8,704 KB |
testcase_03 | AC | 20 ms
8,648 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 | - |
ソースコード
from heapq import * from collections import defaultdict 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(): n, m, s, g = MI() to = defaultdict(list) for _ in range(m): a, b, c = MI() to[a].append([b, c]) to[b].append([a, c]) hp = [] heappush(hp, [0, str(s), s]) fin = [False] * n while hp: d, r, u = heappop(hp) if u == g: r = list(r) print(*r) exit() if fin[u]: continue fin[u] = True for v, c in to[u]: if fin[v]: continue heappush(hp, [d + c, r + str(v), v]) main()