結果

問題 No.2387 Yokan Factory
ユーザー lloyzlloyz
提出日時 2023-07-21 21:50:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,448 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 181,388 KB
最終ジャッジ日時 2024-09-21 23:17:58
合計ジャッジ時間 21,154 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappop, heappush

n, m, x = map(int, input().split())
G = defaultdict(list)
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, a, b))
    G[v].append((u, a, b))

left, right = -1, 10**9 + 10
while right - left > 1:
    mid = (left + right) // 2
    DP = [x + 1 for _ in range(n)]
    DP[0] = 0
    H = [(0, 0)]
    while H:
        cc, cp = heappop(H)
        if cc > DP[cp]:
            continue
        for np, a, b in G[cp]:
            if b < mid:
                continue
            if cc + a >= DP[np]:
                continue
            DP[np] = cc + a
            heappush(H, (cc + a, np))
    if DP[n - 1] == x + 1:
        right = mid
    else:
        left = mid
print(left)
0