結果

問題 No.2387 Yokan Factory
コンテスト
ユーザー miho-4
提出日時 2023-07-21 22:10:51
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 756 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 146 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 144,896 KB
最終ジャッジ日時 2026-04-10 05:09:59
合計ジャッジ時間 9,065 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 1 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
import heapq
n,m,X=map(int,input().split())
edge=[list(map(int,input().split())) for _ in range(m)]
E=[[] for _ in range(n+1)]
for u,v,a,b in edge:
  E[u].append([v,a,b])
  E[v].append([u,a,b])
  
def f(y):
  D=[float("inf")]*(n+1)
  D[1]=0
#  q=deque([1])
  q=[]
  heapq.heappush(q,(0,1))
  while q:
#    x=q.popleft()
    d,x=heapq.heappop(q)
    for e,a,b in E[x]:
      if y<=b and D[x]+a<D[e] and D[x]<=X:
        D[e]=D[x]+a
        heapq.heappush(q,(d+a,e))
#        q.append(e)
#  print(y,D)
  return 0<D[-1]<=X

l,r=0,10**9+1
while 1:
  m=(l+r)//2
  if m<=0:
    exit(print(-1))
  flag=f(m)

  if flag and m==10**9:exit(print(m))
  if flag and f(m+1)==0:
    exit(print(m))
    
  if flag:
    l=m+1
  else:
    r=m-1
0