結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
## 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()