結果
問題 |
No.2805 Go to School
|
ユーザー |
👑 |
提出日時 | 2024-07-12 21:21:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 550 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 297 ms |
コンパイル使用メモリ | 82,836 KB |
実行使用メモリ | 118,424 KB |
最終ジャッジ日時 | 2025-04-09 15:36:43 |
合計ジャッジ時間 | 11,320 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
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 -= 1 v -= 1 edges[u].append((v, w)) edges[v].append((u, w)) T = list(map(int, input().split())) tf = [False] * n for t in T: tf[t - 1] = True inf = 1 << 60 dist = [[inf] * n for _ in range(2)] dist[0][0] = 0 hq = [0] while hq: tmp = heappop(hq) t = tmp & 1 tmp >>= 1 d = tmp // n pos = tmp - d * n if dist[t][pos] < d: continue for npos, c in edges[pos]: nd = d + c if t == 0 and nd >= s + e: continue if nd < dist[t][npos]: dist[t][npos] = nd heappush(hq, (nd * n + npos) * 2 + t) if t == 0 and tf[pos]: nd = max(s, d) + 1 if nd < dist[1][pos]: dist[1][pos] = nd heappush(hq, (nd * n + pos) * 2 + 1) ans = dist[1][n - 1] if ans == inf: ans = -1 print(ans)