結果

問題 No.2387 Yokan Factory
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-01-07 13:30:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,228 ms / 5,000 ms
コード長 1,406 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 267,472 KB
最終ジャッジ日時 2024-01-07 13:31:17
合計ジャッジ時間 37,050 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 41 ms
53,460 KB
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 41 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 40 ms
53,460 KB
testcase_06 AC 40 ms
53,460 KB
testcase_07 AC 41 ms
53,460 KB
testcase_08 AC 41 ms
53,460 KB
testcase_09 AC 43 ms
53,460 KB
testcase_10 AC 42 ms
53,460 KB
testcase_11 AC 41 ms
53,460 KB
testcase_12 AC 41 ms
53,460 KB
testcase_13 AC 41 ms
53,460 KB
testcase_14 AC 40 ms
53,460 KB
testcase_15 AC 1,628 ms
265,896 KB
testcase_16 AC 786 ms
175,120 KB
testcase_17 AC 2,520 ms
264,084 KB
testcase_18 AC 2,106 ms
222,576 KB
testcase_19 AC 2,612 ms
194,360 KB
testcase_20 AC 2,179 ms
177,748 KB
testcase_21 AC 4,049 ms
266,428 KB
testcase_22 AC 2,034 ms
175,824 KB
testcase_23 AC 2,820 ms
215,148 KB
testcase_24 AC 1,376 ms
139,352 KB
testcase_25 AC 1,914 ms
177,204 KB
testcase_26 AC 3,428 ms
234,616 KB
testcase_27 AC 4,228 ms
267,472 KB
testcase_28 AC 133 ms
77,064 KB
testcase_29 AC 155 ms
77,576 KB
testcase_30 AC 154 ms
77,576 KB
testcase_31 AC 139 ms
76,792 KB
testcase_32 AC 105 ms
76,052 KB
testcase_33 AC 102 ms
75,936 KB
testcase_34 AC 182 ms
77,576 KB
testcase_35 AC 148 ms
77,532 KB
testcase_36 AC 94 ms
75,820 KB
testcase_37 AC 44 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

## 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()
0