結果

問題 No.2805 Go to School
ユーザー hirayuu_yc
提出日時 2024-07-04 08:04:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,485 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 179,992 KB
最終ジャッジ日時 2025-04-09 15:36:06
合計ジャッジ時間 26,105 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import*
N,M,L,S,E=map(int,input().split())
gr=[[] for i in range(N*2)]
edge=[]
for i in range(M):
    a,b,t=map(int,input().split())
    gr[(a-1)*2].append(((b-1)*2,t))
    gr[(b-1)*2].append(((a-1)*2,t))
    gr[(a-1)*2+1].append(((b-1)*2+1,t))
    gr[(b-1)*2+1].append(((a-1)*2+1,t))
T=list(map(int,input().split()))
for t in T:
    gr[(t-1)*2].append(((t-1)*2+1,-1))
dist=[1<<60]*N*2
vert=[(0,0)]
while vert:
    dis,pos=heappop(vert)
    if dist[pos]!=1<<60:
        continue
    dist[pos]=dis
    for t,c in gr[pos]:
        nxt=dis+c
        if c==-1:
            if dis>=S+E:
                continue
            nxt=max(S,dis)+1
        heappush(vert,(nxt,t))
if dist[-1]>=1<<60:
    print(-1)
else:
    print(dist[-1])
0