結果

問題 No.2387 Yokan Factory
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-07-21 21:57:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,578 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 81,400 KB
実行使用メモリ 143,632 KB
最終ジャッジ日時 2023-10-21 21:58:58
合計ジャッジ時間 16,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,352 KB
testcase_01 AC 36 ms
53,352 KB
testcase_02 AC 40 ms
53,352 KB
testcase_03 AC 35 ms
53,352 KB
testcase_04 AC 36 ms
53,352 KB
testcase_05 AC 37 ms
53,352 KB
testcase_06 AC 37 ms
53,352 KB
testcase_07 AC 36 ms
53,352 KB
testcase_08 AC 35 ms
53,352 KB
testcase_09 AC 38 ms
53,352 KB
testcase_10 AC 37 ms
53,352 KB
testcase_11 AC 37 ms
53,352 KB
testcase_12 AC 37 ms
53,352 KB
testcase_13 AC 35 ms
53,352 KB
testcase_14 AC 36 ms
53,352 KB
testcase_15 AC 1,020 ms
136,844 KB
testcase_16 AC 656 ms
131,848 KB
testcase_17 AC 968 ms
143,632 KB
testcase_18 AC 1,219 ms
123,316 KB
testcase_19 AC 1,101 ms
109,540 KB
testcase_20 AC 910 ms
106,480 KB
testcase_21 AC 1,578 ms
126,760 KB
testcase_22 AC 777 ms
103,432 KB
testcase_23 AC 1,132 ms
110,900 KB
testcase_24 AC 502 ms
97,892 KB
testcase_25 AC 673 ms
96,856 KB
testcase_26 AC 1,158 ms
114,444 KB
testcase_27 AC 1,571 ms
124,372 KB
testcase_28 AC 106 ms
76,456 KB
testcase_29 AC 129 ms
77,028 KB
testcase_30 AC 112 ms
77,088 KB
testcase_31 AC 115 ms
76,496 KB
testcase_32 AC 86 ms
75,656 KB
testcase_33 AC 98 ms
75,784 KB
testcase_34 AC 131 ms
77,028 KB
testcase_35 AC 114 ms
76,976 KB
testcase_36 AC 88 ms
75,528 KB
testcase_37 AC 37 ms
53,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
n,m,x = map(int,input().split())
size = set()
size.add(1)

e = [[] for i in range(n)]
for _ in range(m):
    u,v,a,b = map(int,input().split())
    size.add(b)
    u,v = u-1,v-1
    e[u].append([v,a,b])
    e[v].append([u,a,b])


size = sorted(size)

l = 0
r = len(size)

inf = 10**20
mod = 1<<20
def search(s):
    dis = [inf]*n
    dis[0] = 0
    h = [0]
    while h:
        d,now = divmod(heappop(h),mod)

        if dis[now] != d:
            continue

        for nex,a,b in e[now]:
            if b < s:
                continue
            if dis[nex] > dis[now]+a:
                dis[nex] = dis[now]+a
                heappush(h,(dis[nex]<<20)+nex)
    return dis[-1]

while r > l+1:
    m = (r+l)//2
    if search(size[m]) <= x:
        l = m
    else:
        r = m


ans = search(size[l])
if ans > x:
    print(-1)
else:
    print(size[l])
0