結果
問題 |
No.2805 Go to School
|
ユーザー |
|
提出日時 | 2024-07-12 21:58:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,263 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 267,408 KB |
最終ジャッジ日時 | 2024-07-12 21:59:12 |
合計ジャッジ時間 | 25,633 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 WA * 9 |
ソースコード
import heapq, sys from collections import defaultdict input = sys.stdin.read data = input().split() N, M, L, S, E = map(int, data[:5]) paths = [(int(data[i]), int(data[i+1]), int(data[i+2])) for i in range(5, 5 + 3 * M, 3)] toilets = list(map(int, data[5 + 3 * M:])) g = defaultdict(dict) for a, b, t in paths: g[a][b] = min(g[a].get(b, float('inf')), t) g[b][a] = min(g[b].get(a, float('inf')), t) def dijkstra(g, start): d = {i: float('inf') for i in g} d[start] = 0 q = [(0, start)] while q: cd, cn = heapq.heappop(q) if cd > d[cn]: continue for n, w in g[cn].items(): dist = cd + w if dist < d[n]: d[n] = dist heapq.heappush(q, (dist, n)) return d try: mt = dijkstra(g, 1) rg = defaultdict(dict) for a in g: for b in g[a]: rg[b][a] = g[a][b] mf = dijkstra(rg, N) min_t = float('inf') for t in toilets: at = mt[t] if at < S: tt = S + 1 + mf[t] elif at <= S + E - 0.99: tt = at + 1 + mf[t] else: continue if tt < min_t: min_t = tt print(-1 if min_t == float('inf') else int(min_t)) except KeyError: print(-1)