結果
問題 | No.2805 Go to School |
ユーザー |
👑 |
提出日時 | 2024-07-12 21:21:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 596 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 81,976 KB |
実行使用メモリ | 120,464 KB |
最終ジャッジ日時 | 2024-07-16 01:37:23 |
合計ジャッジ時間 | 12,192 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
from heapq import *n, m, l, s, e = map(int, input().split())edges = [[] for _ in range(n)]for _ in range(m):u, v, w = map(int, input().split())u -= 1v -= 1edges[u].append((v, w))edges[v].append((u, w))T = list(map(int, input().split()))tf = [False] * nfor t in T:tf[t - 1] = Trueinf = 1 << 60dist = [[inf] * n for _ in range(2)]dist[0][0] = 0hq = [0]while hq:tmp = heappop(hq)t = tmp & 1tmp >>= 1d = tmp // npos = tmp - d * nif dist[t][pos] < d:continuefor npos, c in edges[pos]:nd = d + cif t == 0 and nd >= s + e:continueif nd < dist[t][npos]:dist[t][npos] = ndheappush(hq, (nd * n + npos) * 2 + t)if t == 0 and tf[pos]:nd = max(s, d) + 1if nd < dist[1][pos]:dist[1][pos] = ndheappush(hq, (nd * n + pos) * 2 + 1)ans = dist[1][n - 1]if ans == inf:ans = -1print(ans)