結果

問題 No.2387 Yokan Factory
ユーザー ああいいああいい
提出日時 2023-07-22 17:08:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,515 ms / 5,000 ms
コード長 1,546 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 81,628 KB
実行使用メモリ 208,464 KB
最終ジャッジ日時 2023-10-23 23:36:41
合計ジャッジ時間 20,858 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,444 KB
testcase_01 AC 41 ms
53,444 KB
testcase_02 AC 37 ms
53,444 KB
testcase_03 AC 38 ms
53,444 KB
testcase_04 AC 37 ms
53,444 KB
testcase_05 AC 37 ms
53,444 KB
testcase_06 AC 36 ms
53,444 KB
testcase_07 AC 41 ms
53,444 KB
testcase_08 AC 41 ms
53,444 KB
testcase_09 AC 37 ms
53,444 KB
testcase_10 AC 37 ms
53,444 KB
testcase_11 AC 37 ms
53,444 KB
testcase_12 AC 37 ms
53,444 KB
testcase_13 AC 38 ms
53,444 KB
testcase_14 AC 36 ms
53,444 KB
testcase_15 AC 974 ms
131,904 KB
testcase_16 AC 446 ms
117,184 KB
testcase_17 AC 1,736 ms
208,464 KB
testcase_18 AC 1,470 ms
126,960 KB
testcase_19 AC 1,116 ms
119,092 KB
testcase_20 AC 909 ms
109,196 KB
testcase_21 AC 2,130 ms
142,036 KB
testcase_22 AC 851 ms
103,396 KB
testcase_23 AC 2,220 ms
125,092 KB
testcase_24 AC 1,072 ms
107,208 KB
testcase_25 AC 1,019 ms
105,268 KB
testcase_26 AC 2,515 ms
137,392 KB
testcase_27 AC 942 ms
124,656 KB
testcase_28 AC 82 ms
74,676 KB
testcase_29 AC 113 ms
76,808 KB
testcase_30 AC 113 ms
76,668 KB
testcase_31 AC 118 ms
76,520 KB
testcase_32 AC 89 ms
76,132 KB
testcase_33 AC 99 ms
76,188 KB
testcase_34 AC 149 ms
77,532 KB
testcase_35 AC 117 ms
76,616 KB
testcase_36 AC 71 ms
70,544 KB
testcase_37 AC 40 ms
53,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
rr = sys.stdin
N,M,X = map(int,rr.readline().split())
BB = 0
G = [[] for _ in range(N)]
for _ in range(M):
    u,v,a,b = map(int,rr.readline().split())
    u -= 1
    v -= 1
    if BB < b:BB = b
    G[u].append((b,a,v))
    G[v].append((b,a,u))
for i in range(N):
    G[i].sort(reverse = True)
X = min(X,10 ** 14)
inf = 1 << 50
B = 47
mask = (1 << B) - 1
def calc(k):
    
    dist = [inf] * N
    dist[0] = 0
    q = [0]
    while q:
        """
        U = heapq.heappop(q)
        d = U >> B
        now = U & mask
        """
        if dist[now] > d:continue
        if now == N - 1:break
        for b,a,v in G[now]:
            if b < k:break
            if dist[v] > d + a:
                dist[v] = d + a
                heapq.heappush(q,((d + a) << B) + v)
    return dist[-1] <= X
end = BB + 1
start = 0
while end - start > 1:
    mid = end + start >> 1
    k = mid
    dist = [inf] * N
    dist[0] = 0
    f = [False] * N
    q = [(0,0)]
    while q:
        """
        U = heapq.heappop(q)
        d = U >> B
        now = U & mask
        """
        d,now = heapq.heappop(q)
        if f[now]:continue
        f[now] = True
        if now == N - 1:break
        for b,a,v in G[now]:
            if b < k:break
            if dist[v] > d + a:
                dist[v] = d + a
                heapq.heappush(q,(d + a,v))
    if  dist[-1] <= X:
        start = mid
    else:
        end = mid
    """
    if calc(mid):
        start = mid
    else:
        end = mid
    """
print(start if start != 0 else -1)
0