結果

問題 No.2805 Go to School
ユーザー hato336
提出日時 2024-07-12 21:28:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,045 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 166,120 KB
最終ジャッジ日時 2025-04-09 15:37:12
合計ジャッジ時間 20,876 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
#input = sys.stdin.readline
#n = int(input())
#
#alist = []
input = sys.stdin.readline
n,m,l,s,e = map(int,input().split())
edge = [[] for i in range(n*2)]
for i in range(m):
    u,v,t = map(int,input().split())
    u-=1
    v-=1
    edge[2*u].append((2*v,t))
    edge[2*v].append((2*u,t))
    edge[2*u+1].append((2*v+1,t))
    edge[2*v+1].append((2*u+1,t))
toile = set(map(lambda x:int(x)-1,input().split()))
start = 0
d = []
dist = [10**18 for i in range(n+n)]
heapq.heappush(d,(0,0))
dist[start] = 0
while d:
    _,now = heapq.heappop(d)
    if _ > dist[now]:
        continue
    y = now % 2
    if y == 0 and now // 2 in toile:
        x = dist[now]
        if x < s:
            c = s + 1
        elif s <= x < s+e:
            c = x + 1
        else:
            c = 10**19
        if dist[now+1] > c:
            dist[now+1] = c
            heapq.heappush(d,(dist[now+1],now+1))
    for to,cost in edge[now]:
        if dist[to] > dist[now] + cost:
            dist[to] = dist[now] + cost
            heapq.heappush(d,(dist[to],to))
print(dist[-1] if dist[-1] != 10**18 else -1)
0