結果

問題 No.2387 Yokan Factory
ユーザー i_takui_taku
提出日時 2023-07-21 21:51:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,393 ms / 5,000 ms
コード長 1,026 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 81,580 KB
実行使用メモリ 203,456 KB
最終ジャッジ日時 2023-10-21 21:51:38
合計ジャッジ時間 28,741 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,456 KB
testcase_01 AC 43 ms
55,456 KB
testcase_02 AC 43 ms
55,456 KB
testcase_03 AC 44 ms
55,456 KB
testcase_04 AC 44 ms
55,456 KB
testcase_05 AC 44 ms
55,456 KB
testcase_06 AC 43 ms
55,456 KB
testcase_07 AC 43 ms
55,456 KB
testcase_08 AC 44 ms
55,456 KB
testcase_09 AC 44 ms
55,456 KB
testcase_10 AC 44 ms
55,456 KB
testcase_11 AC 44 ms
55,456 KB
testcase_12 AC 44 ms
55,456 KB
testcase_13 AC 45 ms
55,456 KB
testcase_14 AC 44 ms
55,456 KB
testcase_15 AC 1,259 ms
155,476 KB
testcase_16 AC 660 ms
160,640 KB
testcase_17 AC 1,989 ms
203,456 KB
testcase_18 AC 1,596 ms
154,632 KB
testcase_19 AC 2,299 ms
138,128 KB
testcase_20 AC 1,762 ms
132,116 KB
testcase_21 AC 2,967 ms
146,656 KB
testcase_22 AC 1,678 ms
122,128 KB
testcase_23 AC 2,505 ms
146,584 KB
testcase_24 AC 897 ms
112,248 KB
testcase_25 AC 1,524 ms
121,772 KB
testcase_26 AC 2,765 ms
143,644 KB
testcase_27 AC 3,393 ms
180,192 KB
testcase_28 AC 109 ms
77,208 KB
testcase_29 AC 146 ms
78,092 KB
testcase_30 AC 127 ms
78,016 KB
testcase_31 AC 127 ms
77,328 KB
testcase_32 AC 91 ms
76,216 KB
testcase_33 AC 98 ms
76,452 KB
testcase_34 AC 144 ms
77,820 KB
testcase_35 AC 122 ms
77,324 KB
testcase_36 AC 97 ms
76,420 KB
testcase_37 AC 44 ms
55,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline()[:-1]
from heapq import heappush, heappop
from collections import defaultdict

N, M, X = map(int, input().split())
INF = float('inf')
g = [defaultdict(list) for _ in range(N)]

def main():
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u -= 1; v -= 1
        g[u][v].append((a, b))
        g[v][u].append((a, b))

    ok = 0
    ng = 1 << 60
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if dijkstra(mid):
            ok = mid
        else:
            ng = mid
    print(ok if 0 < ok else -1)
    
def dijkstra(s):
    hq = [(0, 0)]
    dist = [INF] * N
    dist[0] = 0
    while hq:
        d, u = heappop(hq)
        if dist[u] < d:
            continue
        for v in g[u]:
            for a, b in g[u][v]:
                if b < s:
                    continue
                if dist[u] + a < dist[v]:
                    dist[v] = dist[u] + a
                    heappush(hq, (dist[v], v))
    return dist[N - 1] <= X

main()
0