結果
問題 | No.2387 Yokan Factory |
ユーザー | LyricalMaestro |
提出日時 | 2024-01-07 13:30:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,707 ms / 5,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 268,972 KB |
最終ジャッジ日時 | 2024-09-27 19:22:43 |
合計ジャッジ時間 | 33,079 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,864 KB |
testcase_01 | AC | 45 ms
52,736 KB |
testcase_02 | AC | 40 ms
52,608 KB |
testcase_03 | AC | 41 ms
52,608 KB |
testcase_04 | AC | 40 ms
52,736 KB |
testcase_05 | AC | 42 ms
52,864 KB |
testcase_06 | AC | 41 ms
52,864 KB |
testcase_07 | AC | 41 ms
52,992 KB |
testcase_08 | AC | 39 ms
52,608 KB |
testcase_09 | AC | 40 ms
52,608 KB |
testcase_10 | AC | 39 ms
52,608 KB |
testcase_11 | AC | 38 ms
52,352 KB |
testcase_12 | AC | 41 ms
52,992 KB |
testcase_13 | AC | 39 ms
52,608 KB |
testcase_14 | AC | 41 ms
52,352 KB |
testcase_15 | AC | 1,536 ms
266,284 KB |
testcase_16 | AC | 708 ms
174,976 KB |
testcase_17 | AC | 2,338 ms
265,000 KB |
testcase_18 | AC | 1,843 ms
222,684 KB |
testcase_19 | AC | 2,391 ms
194,528 KB |
testcase_20 | AC | 1,995 ms
178,160 KB |
testcase_21 | AC | 3,669 ms
268,188 KB |
testcase_22 | AC | 1,809 ms
176,564 KB |
testcase_23 | AC | 2,599 ms
215,244 KB |
testcase_24 | AC | 1,255 ms
139,372 KB |
testcase_25 | AC | 1,715 ms
177,456 KB |
testcase_26 | AC | 3,217 ms
233,636 KB |
testcase_27 | AC | 3,707 ms
268,972 KB |
testcase_28 | AC | 114 ms
77,200 KB |
testcase_29 | AC | 141 ms
77,712 KB |
testcase_30 | AC | 136 ms
78,060 KB |
testcase_31 | AC | 133 ms
77,288 KB |
testcase_32 | AC | 98 ms
76,544 KB |
testcase_33 | AC | 93 ms
76,160 KB |
testcase_34 | AC | 144 ms
78,012 KB |
testcase_35 | AC | 133 ms
78,144 KB |
testcase_36 | AC | 86 ms
76,376 KB |
testcase_37 | AC | 42 ms
52,992 KB |
ソースコード
## https://yukicoder.me/problems/no/2387 import heapq def solve(N, next_node, X, width): fix = {} seen = {0:0} queue= [] heapq.heappush(queue, (0, 0)) while len(queue) > 0: cost, v = heapq.heappop(queue) if v in fix: continue fix[v] = cost for next_v, a, b in next_node[v]: if next_v in fix: continue if b < width: continue new_cost = cost + a if next_v not in seen or seen[next_v] > new_cost: seen[next_v] = new_cost heapq.heappush(queue, (new_cost, next_v)) if (N - 1) not in fix: return False else: return fix[N - 1] <= X def main(): N, M, X = map(int, input().split()) next_node = [[] for _ in range(N)] max_b = 0 for _ in range(M): u, v, a,b= map(int, input().split()) next_node[u - 1].append((v - 1, a, b)) next_node[v - 1].append((u - 1, a, b)) max_b = max(max_b, b) low = 0 high = max_b while high - low > 1: mid = (high + low) // 2 if solve(N, next_node, X, mid): low = mid else: high = mid if solve(N, next_node, X, high): v = high else: v = low if v == 0: print(-1) else: print(v) if __name__ == "__main__": main()