結果
問題 | No.2805 Go to School |
ユーザー |
|
提出日時 | 2025-03-08 09:09:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,209 ms / 2,000 ms |
コード長 | 914 bytes |
コンパイル時間 | 496 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 126,000 KB |
最終ジャッジ日時 | 2025-03-08 09:10:21 |
合計ジャッジ時間 | 23,464 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
import heapqN,M,L,S,E = map(int,input().split())G = {i:[] for i in range(1,N+1)}for _ in range(M):a,b,t = map(int,input().split())G[a].append((b,t))G[b].append((a,t))T = list(map(int,input().split()))INFTY = 10**15dist1 = [INFTY for _ in range(N+1)]dist1[1] = 0que = [(0,1)]while que:d,x = heapq.heappop(que)if dist1[x]<d:continuefor y,t in G[x]:if dist1[y]>d+t:dist1[y] = d+theapq.heappush(que,(d+t,y))T1 = []for a in T:if dist1[a]<=S+E:T1.append(a)dist2 = [INFTY for _ in range(N+1)]dist2[N] = 0que = [(0,N)]while que:d,x = heapq.heappop(que)if dist2[x]<d:continuefor y,t in G[x]:if dist2[y]>d+t:dist2[y] = d+theapq.heappush(que,(d+t,y))ans = INFTYfor a in T1:d = max(dist1[a],S)+1+dist2[a]ans = min(ans,d)if ans>=INFTY:print(-1)else:print(ans)