結果
問題 | No.2805 Go to School |
ユーザー | NP |
提出日時 | 2024-07-12 22:04:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,550 ms / 2,000 ms |
コード長 | 1,431 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 267,076 KB |
最終ジャッジ日時 | 2024-07-16 01:40:21 |
合計ジャッジ時間 | 23,237 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,256 KB |
testcase_01 | AC | 44 ms
56,248 KB |
testcase_02 | AC | 42 ms
54,560 KB |
testcase_03 | AC | 40 ms
55,860 KB |
testcase_04 | AC | 511 ms
213,668 KB |
testcase_05 | AC | 760 ms
171,180 KB |
testcase_06 | AC | 521 ms
125,536 KB |
testcase_07 | AC | 443 ms
121,616 KB |
testcase_08 | AC | 620 ms
166,740 KB |
testcase_09 | AC | 507 ms
124,256 KB |
testcase_10 | AC | 429 ms
125,128 KB |
testcase_11 | AC | 1,550 ms
266,260 KB |
testcase_12 | AC | 997 ms
179,072 KB |
testcase_13 | AC | 1,309 ms
218,072 KB |
testcase_14 | AC | 316 ms
108,680 KB |
testcase_15 | AC | 42 ms
55,956 KB |
testcase_16 | AC | 39 ms
55,208 KB |
testcase_17 | AC | 40 ms
55,172 KB |
testcase_18 | AC | 655 ms
139,208 KB |
testcase_19 | AC | 543 ms
127,400 KB |
testcase_20 | AC | 952 ms
182,444 KB |
testcase_21 | AC | 1,389 ms
264,480 KB |
testcase_22 | AC | 687 ms
163,480 KB |
testcase_23 | AC | 998 ms
178,744 KB |
testcase_24 | AC | 943 ms
176,684 KB |
testcase_25 | AC | 345 ms
134,596 KB |
testcase_26 | AC | 984 ms
267,076 KB |
testcase_27 | AC | 559 ms
206,044 KB |
testcase_28 | AC | 88 ms
82,972 KB |
testcase_29 | AC | 132 ms
101,564 KB |
testcase_30 | AC | 292 ms
154,584 KB |
testcase_31 | AC | 506 ms
145,848 KB |
testcase_32 | AC | 776 ms
264,492 KB |
testcase_33 | AC | 1,121 ms
257,144 KB |
testcase_34 | AC | 59 ms
68,796 KB |
testcase_35 | AC | 62 ms
71,048 KB |
testcase_36 | AC | 613 ms
140,112 KB |
testcase_37 | AC | 570 ms
163,700 KB |
testcase_38 | AC | 967 ms
217,504 KB |
ソースコード
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 min_time_to = dijkstra(g, 1) reverse_g = defaultdict(dict) for a in g: for b in g[a]: reverse_g[b][a] = g[a][b] min_time_from = dijkstra(reverse_g, N) min_time = float('inf') for toilet in toilets: if toilet in min_time_to and toilet in min_time_from: arrival_time = min_time_to[toilet] if arrival_time < S: total_time = S + 1 + min_time_from[toilet] elif arrival_time <= S + E - 0.99: total_time = arrival_time + 1 + min_time_from[toilet] else: continue if total_time < min_time: min_time = total_time print(-1 if min_time == float('inf') else int(min_time))