結果
問題 |
No.160 最短経路のうち辞書順最小
|
ユーザー |
![]() |
提出日時 | 2021-02-26 23:54:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 817 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 14,080 KB |
最終ジャッジ日時 | 2024-10-02 16:34:30 |
合計ジャッジ時間 | 2,811 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 WA * 18 |
ソースコード
import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10**9 N, M, S, G = map(int, input().split()) edge = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) edge[a].append((b, c)) edge[b].append((a, c)) dist = [inf] * N prev = [N] * N dist[S] = 0 que = [(0, S)] while que: ds, s = heapq.heappop(que) if dist[s] < ds: continue for t, dt in edge[s]: if dist[t] > ds + dt: dist[t] = ds + dt heapq.heappush(que, (ds + dt, t)) prev[t] = s elif dist[t] == ds + dt: if prev[t] > s: prev[t] = s heapq.heappush(que, (ds + dt, t)) ans = [] now = G while now < N: ans.append(now) now = prev[now] ans.reverse() print(*ans)