結果
問題 |
No.2805 Go to School
|
ユーザー |
![]() |
提出日時 | 2024-09-27 21:59:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,075 ms / 2,000 ms |
コード長 | 746 bytes |
コンパイル時間 | 364 ms |
コンパイル使用メモリ | 82,336 KB |
実行使用メモリ | 121,468 KB |
最終ジャッジ日時 | 2025-04-09 15:43:41 |
合計ジャッジ時間 | 17,089 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
from heapq import heappush,heappop def dijkstra(v): que=[(0,v)] cost=[float('INF')]*n cost[v]=0 while que: c,v=heappop(que) if c>cost[v]:continue for nc,nv in graph[v]: if cost[nv]>cost[v]+nc: cost[nv]=cost[v]+nc heappush(que,(cost[nv],nv)) return cost import sys input=sys.stdin.readline n,m,l,s,e=map(int,input().split()) graph=[[] for _ in range(n)] for _ in range(m): a,b,c=map(int,input().split()) a,b=a-1,b-1 graph[a].append((c,b)) graph[b].append((c,a)) T=list(map(lambda x:int(x)-1,input().split())) dist1=dijkstra(0) distn=dijkstra(n-1) ans=float('INF') for t in T: if dist1[t]>=s+e:continue ans=min(ans,max(s,dist1[t])+1+distn[t]) print(ans if ans!=float('INF') else -1)