結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-09-13 04:38:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 4,450 ms / 5,000 ms |
| コード長 | 1,152 bytes |
| コンパイル時間 | 778 ms |
| コンパイル使用メモリ | 82,596 KB |
| 実行使用メモリ | 269,076 KB |
| 最終ジャッジ日時 | 2025-09-13 04:39:41 |
| 合計ジャッジ時間 | 23,792 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
from collections import defaultdict
from heapq import heappush, heappop
INF = 1 << 60
N, M, X = map(int, input().split())
adj = defaultdict(list)
for _ in range(M):
u, v, a, b = map(int, input().split())
u -= 1
v -= 1
adj[u].append((v, a, b))
adj[v].append((u, a, b))
def bsearch(low: int, high: int, pred, is_complement=False) -> int:
test = (lambda x: not pred(x)) if is_complement else pred
assert test(low)
lo = low
hi = high
res = low
while lo <= hi:
m = (lo + hi) // 2
if test(m):
res = max(res, m)
lo = m + 1
else:
hi = m - 1
return res + 1 if is_complement else res
# 大きさ m を輸送できるか
def can(m: int) -> bool:
q = [(0, 0)]
used = [INF] * N
while q:
tm, v = heappop(q)
if v == N-1: return True
if used[v] <= tm: continue
used[v] = tm
for to, a, b in adj[v]:
if b < m: continue
if tm + a > X: continue
heappush(q, (tm + a, to))
return False
if can(1):
ans = bsearch(1, INF, can)
print(ans)
else:
print(-1)
norioc