結果

問題 No.2387 Yokan Factory
ユーザー Navier_Boltzmann
提出日時 2023-07-24 03:44:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,681 ms / 5,000 ms
コード長 1,007 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 181,376 KB
最終ジャッジ日時 2024-09-25 06:31:26
合計ジャッジ時間 19,709 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
sys.setrecursionlimit(3*10**5)
input = sys.stdin.readline
INF = (1<<60)
N,M,X = map(int,input().split())
e = [[] for _ in range(N)]
for _ in range(M):
    u,v,a,b = map(int,input().split())
    u -= 1
    v -= 1
    e[u].append((v,a,b))
    e[v].append((u,a,b))
    
def dijkstra(s,e,t):
    
    N = len(e)
    dist = [INF]*N
    dist[s]=0
    h = []
    heappush(h,(0,s))
    while h:
        nw,v = heappop(h)
        if dist[v]!=nw:
            continue
        for iv,ic,iw in e[v]:
            if iw<t:
                continue
            nc = ic + nw
            if nc < dist[iv]:
                dist[iv] = nc
                heappush(h,(nc,iv))
    return dist


def is_ok(T):
    D = dijkstra(0,e,T)
    return D[-1]<=X

if not is_ok(1):
    print(-1)
    exit()
y = 10**9 + 100
x = 1
while y-x>1:
    mid = (y+x)//2
    if is_ok(mid):
        x = mid
    else:
        y = mid
print(x)
0