結果

問題 No.160 最短経路のうち辞書順最小
ユーザー 👑 rin204rin204
提出日時 2022-07-05 16:46:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 77,840 KB
最終ジャッジ日時 2023-08-22 05:24:11
合計ジャッジ時間 5,406 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,332 KB
testcase_01 AC 78 ms
70,932 KB
testcase_02 AC 79 ms
71,036 KB
testcase_03 AC 76 ms
71,092 KB
testcase_04 AC 117 ms
77,608 KB
testcase_05 AC 123 ms
77,692 KB
testcase_06 AC 128 ms
77,520 KB
testcase_07 AC 117 ms
77,392 KB
testcase_08 AC 114 ms
77,164 KB
testcase_09 AC 112 ms
77,184 KB
testcase_10 AC 112 ms
77,400 KB
testcase_11 AC 113 ms
77,224 KB
testcase_12 AC 114 ms
77,408 KB
testcase_13 AC 110 ms
77,236 KB
testcase_14 AC 109 ms
77,408 KB
testcase_15 AC 113 ms
77,840 KB
testcase_16 AC 111 ms
77,652 KB
testcase_17 AC 112 ms
77,420 KB
testcase_18 AC 112 ms
77,392 KB
testcase_19 AC 112 ms
77,396 KB
testcase_20 AC 115 ms
77,296 KB
testcase_21 AC 113 ms
77,372 KB
testcase_22 AC 110 ms
77,524 KB
testcase_23 AC 114 ms
77,368 KB
testcase_24 AC 115 ms
77,448 KB
testcase_25 AC 119 ms
77,464 KB
testcase_26 AC 111 ms
77,188 KB
testcase_27 AC 84 ms
71,136 KB
testcase_28 AC 124 ms
77,368 KB
testcase_29 AC 80 ms
71,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m, s, g = map(int, input().split())

edges = [[] for _ in range(n)]
for _ in range(m):
    u, v, c = map(int, input().split())
    edges[u].append((v, c))
    edges[v].append((u, c))

dist = [1 << 30] * n
dist[g] = 0
nex = [-1] * n
hq = [g]
while hq:
    tmp = heappop(hq)
    d = tmp // n
    pos = tmp - d * n
    if dist[pos] < d:
        continue
    for npos, c in edges[pos]:
        tmp = c + d
        if tmp < dist[npos]:
            dist[npos] = tmp
            heappush(hq, tmp * n + npos)
            nex[npos] = pos
        elif tmp == dist[npos] and pos < nex[npos]:
            nex[npos] = pos
ans = []
while s != -1:
    ans.append(s)
    s = nex[s]
print(*ans)
0