結果

問題 No.2387 Yokan Factory
ユーザー rlangevinrlangevin
提出日時 2023-07-21 21:42:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,985 ms / 5,000 ms
コード長 1,447 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 278,176 KB
最終ジャッジ日時 2023-10-21 21:41:12
合計ジャッジ時間 16,881 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,508 KB
testcase_01 AC 34 ms
53,508 KB
testcase_02 AC 32 ms
53,508 KB
testcase_03 AC 33 ms
53,508 KB
testcase_04 AC 34 ms
53,508 KB
testcase_05 AC 34 ms
53,508 KB
testcase_06 AC 34 ms
53,508 KB
testcase_07 AC 36 ms
53,508 KB
testcase_08 AC 34 ms
53,508 KB
testcase_09 AC 34 ms
53,508 KB
testcase_10 AC 34 ms
53,508 KB
testcase_11 AC 35 ms
53,508 KB
testcase_12 AC 34 ms
53,508 KB
testcase_13 AC 34 ms
53,508 KB
testcase_14 AC 33 ms
53,508 KB
testcase_15 AC 1,113 ms
270,044 KB
testcase_16 AC 667 ms
255,056 KB
testcase_17 AC 1,314 ms
271,260 KB
testcase_18 AC 1,554 ms
266,016 KB
testcase_19 AC 1,455 ms
272,036 KB
testcase_20 AC 991 ms
237,948 KB
testcase_21 AC 1,802 ms
278,176 KB
testcase_22 AC 873 ms
226,200 KB
testcase_23 AC 1,985 ms
274,404 KB
testcase_24 AC 1,007 ms
219,128 KB
testcase_25 AC 153 ms
86,908 KB
testcase_26 AC 213 ms
94,168 KB
testcase_27 AC 189 ms
98,112 KB
testcase_28 AC 91 ms
76,496 KB
testcase_29 AC 95 ms
77,388 KB
testcase_30 AC 113 ms
77,216 KB
testcase_31 AC 117 ms
77,292 KB
testcase_32 AC 89 ms
76,216 KB
testcase_33 AC 88 ms
76,240 KB
testcase_34 AC 119 ms
77,216 KB
testcase_35 AC 68 ms
74,848 KB
testcase_36 AC 66 ms
73,972 KB
testcase_37 AC 41 ms
59,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappush, heappop
inf = float('inf')


def dijkstra(s, g, N, G):
    # ゴールがない場合はg=-1とする。

    def cost(v, m):
        return v * N + m

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [cost(0, s)]
    while Q:
        c, m = divmod(heappop(Q), N)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, cost(newdist, u))
    return dist


N, M, X = map(int, input().split())
Edge = []
for i in range(M):
    Edge.append(list(map(int, input().split())))


def check(m):
    G = [[] for i in range(N)]
    for u, v, a, b in Edge:
        if b < m:
            continue
        u, v = u - 1, v - 1
        G[u].append((v, a))
        G[v].append((u, a))
        
    D = dijkstra(0, N - 1, N, G)
    return D[-1] <= X
         

if not check(0):
    print(-1)
    exit()
    
yes = 0
no = 10 ** 18 + 5
while no - yes != 1:
    mid = (yes + no)//2
    if check(mid):
        yes = mid
    else:
        no = mid
        
print(yes)
0