結果

問題 No.2805 Go to School
ユーザー moon17
提出日時 2024-07-13 20:26:42
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 545 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 82,640 KB
実行使用メモリ 146,364 KB
最終ジャッジ日時 2025-04-09 15:42:11
合計ジャッジ時間 15,979 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import*
(n,m,l,s,e),*es,ts=[[*map(int,s.split())]for s in open(0)]
g=[[]for _ in range(n)]
for a,b,t in es:
  a-=1;b-=1
  g[a]+=(b,t),
  g[b]+=(a,t),
INF=1<<60
def f(x):
  s=[INF]*n
  s[x]=0
  q=[(0,x)]
  while q:
    c,p=heappop(q)
    if s[p]<c:
      continue
    for v,nc in g[p]:
      if s[v]>c+nc:
        s[v]=c+nc
        heappush(q,(s[v],v))
  return s
s0=f(0)
sn=f(n-1)
ans=INF
for i in ts:
  i-=1
  a=s0[i]+sn[i]+1
  if s0[i]<=s:
    a+=abs(s-s0[i])
  elif s+e<s0[i]:
    continue
  ans=min(ans,a)
print([-1,ans][ans<INF])
0