結果

問題 No.2387 Yokan Factory
ユーザー 👑 timitimi
提出日時 2024-02-14 20:02:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,115 ms / 5,000 ms
コード長 1,280 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 195,848 KB
最終ジャッジ日時 2024-02-14 20:02:25
合計ジャッジ時間 17,811 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 40 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 37 ms
53,460 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 38 ms
53,460 KB
testcase_15 AC 1,028 ms
125,488 KB
testcase_16 AC 428 ms
114,404 KB
testcase_17 AC 1,983 ms
195,848 KB
testcase_18 AC 1,461 ms
120,388 KB
testcase_19 AC 1,353 ms
113,312 KB
testcase_20 AC 973 ms
103,868 KB
testcase_21 AC 2,034 ms
127,364 KB
testcase_22 AC 765 ms
99,756 KB
testcase_23 AC 2,115 ms
116,700 KB
testcase_24 AC 975 ms
103,576 KB
testcase_25 AC 227 ms
86,024 KB
testcase_26 AC 323 ms
94,456 KB
testcase_27 AC 293 ms
96,344 KB
testcase_28 AC 90 ms
76,712 KB
testcase_29 AC 111 ms
76,840 KB
testcase_30 AC 109 ms
76,696 KB
testcase_31 AC 114 ms
76,316 KB
testcase_32 AC 88 ms
76,256 KB
testcase_33 AC 86 ms
76,376 KB
testcase_34 AC 131 ms
77,336 KB
testcase_35 AC 70 ms
72,868 KB
testcase_36 AC 63 ms
68,328 KB
testcase_37 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  from sys import stdin, setrecursionlimit
  input = stdin.readline
  readline = stdin.readline
 
  import heapq
  def dijkstra(p):
      hq=[(0,0)]
      heapq.heapify(hq) # リストを優先度付きキューに変換
      cost=[10**18+1]*N # 行ったことのないところはinf
      cost[0]=0 # 開始地点は0
      while hq:
        c,v=heapq.heappop(hq)
        if N-1==v:
          break
        if c>cost[v]: # コストが現在のコストよりも高ければスルー v:now u:nex
          continue
        for d,u,pp in E[v]:
          if p>pp:
            break
          tmp=d+cost[v]
          if tmp<cost[u]:
            cost[u]=tmp
            heapq.heappush(hq,(tmp,u))
      return cost
  
  N,M,X=map(int,input().split())
  E=[[] for _ in range(N)]
  ma=0
  for i in range(M):
    a,b,t,x=map(int,input().split())
    a-=1;b-=1
    ma=max(ma,x)
    E[a].append((t,b,x))
    E[b].append((t,a,x))
    
  for i in range(N):
    E[i].sort(key=lambda x:x[2],reverse=True)
  
  A=dijkstra(10**9)
  if A[-1]<=X:
    print(10**9)
    exit()
  A=dijkstra(0)
  if A[-1]>X:
    print(-1)
    exit()
  
  
  ok,ng=0,ma+1
  while (ng-ok)>1:
    mid=(ok+ng)//2
    A=dijkstra(mid)
    if A[-1]>X:
      ng=mid
    else:
      ok=mid
  print(ok)
main()
0