結果
問題 | No.2805 Go to School |
ユーザー |
![]() |
提出日時 | 2024-07-12 21:31:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,063 ms / 2,000 ms |
コード長 | 890 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,060 KB |
実行使用メモリ | 123,800 KB |
最終ジャッジ日時 | 2024-07-16 01:37:51 |
合計ジャッジ時間 | 17,099 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
from heapq import heappush, heappopN, M, L, S, E = map(int, input().split())G = [[] for _ in range(N)]for _ in range(M):a, b, t = map(int, input().split())G[a-1].append((b-1, t))G[b-1].append((a-1, t))T = list(map(int, input().split()))INF = 10**18def dijkstra(start):dist = [INF]*Ndist[start] = 0visited = [False]*Nque = [(0, start)]while que:d, now = heappop(que)if visited[now]:continuevisited[now] = Truefor next, weight in G[now]:if dist[now]+weight < dist[next]:dist[next] = dist[now]+weightheappush(que, (dist[next], next))return distdistS = dijkstra(0)distG = dijkstra(N-1)ans = INFfor i in range(L):if distS[T[i]-1] <= S+E-1:ans = min(ans, max(distS[T[i]-1], S)+1+distG[T[i]-1])print(ans if ans != INF else -1)