結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー |
![]() |
提出日時 | 2025-01-03 22:48:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 848 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 82,480 KB |
実行使用メモリ | 81,416 KB |
最終ジャッジ日時 | 2025-01-03 22:48:21 |
合計ジャッジ時間 | 4,280 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 WA * 18 |
ソースコード
from heapq import *def dijkstra(start, goal):D[start] = 0q = []heappush(q, (0, start))while len(q) > 0:d, u = heappop(q)if u == goal:returnif d > D[u]: continuefor v, c in E[u]:if D[v] == D[u] + c:if P[v] > u:P[v] = uif D[v] > D[u] + c:D[v] = D[u] + cheappush(q, (D[v], v))P[v] = ureturn []N,M,S,G = map(int,input().split())ABC = [list(map(int,input().split())) for _ in range(M)]E = [[] for _ in range(N + 1)]for a, b, c in ABC:E[a].append([b, c])E[b].append([a, c])INF = 10 ** 7D = [INF] * (N + 1)P = [-1] * (N + 1)dijkstra(S, G)now = Gans = [G]while now != S:now = P[now]ans.append(now)ans = reversed(ans)print(*ans)