結果

問題 No.2805 Go to School
コンテスト
ユーザー flippergo
提出日時 2026-02-27 09:49:20
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,115 ms / 2,000 ms
コード長 813 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 423 ms
コンパイル使用メモリ 77,896 KB
実行使用メモリ 122,840 KB
最終ジャッジ日時 2026-02-27 09:49:42
合計ジャッジ時間 20,871 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
N,M,L,S,E = map(int, input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b,c = map(int, input().split())
    G[a].append((b,c))
    G[b].append((a,c))
T = list(map(int, input().split()))
INFTY = 10**15
DF = [INFTY]*(N+1)
DF[1] = 0
heap = [(0,1)]
while heap:
    d,v = heapq.heappop(heap)
    if DF[v]<d:continue
    for w,c in G[v]:
        if DF[w]>d+c:
            DF[w] = d+c
            heapq.heappush(heap,(DF[w],w))
DG = [INFTY]*(N+1)
DG[N] = 0
heap = [(0,N)]
while heap:
    d,v = heapq.heappop(heap)
    if DG[v]<d:continue
    for w,c in G[v]:
        if DG[w]>d+c:
            DG[w] = d+c
            heapq.heappush(heap,(DG[w],w))
ans = INFTY
for t in T:
    if DF[t]<S+E:
        ans = min(ans,max(S,DF[t])+1+DG[t])
if ans==INFTY:
    print(-1)
else:
    print(ans)
0