結果
問題 | No.2805 Go to School |
ユーザー |
![]() |
提出日時 | 2024-09-27 21:58:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,275 ms / 2,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 82,544 KB |
実行使用メモリ | 122,444 KB |
最終ジャッジ日時 | 2024-09-27 21:58:29 |
合計ジャッジ時間 | 22,448 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
from heapq import heappush,heappopdef dijkstra(v):que=[(0,v)]cost=[float('INF')]*ncost[v]=0while que:c,v=heappop(que)if c>cost[v]:continuefor nc,nv in graph[v]:if cost[nv]>cost[v]+nc:cost[nv]=cost[v]+ncheappush(que,(cost[nv],nv))return costn,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-1graph[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:continueans=min(ans,max(s,dist1[t])+1+distn[t])print(ans if ans!=float('INF') else -1)