結果

問題 No.2739 Time is money
ユーザー ButterflvButterflv
提出日時 2024-04-23 20:17:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,252 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 163,388 KB
最終ジャッジ日時 2024-04-23 20:17:55
合計ジャッジ時間 17,239 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,992 KB
testcase_01 AC 41 ms
52,480 KB
testcase_02 AC 246 ms
111,428 KB
testcase_03 AC 1,098 ms
148,856 KB
testcase_04 AC 236 ms
111,020 KB
testcase_05 AC 803 ms
128,968 KB
testcase_06 AC 1,057 ms
147,844 KB
testcase_07 AC 1,103 ms
156,324 KB
testcase_08 AC 1,187 ms
159,720 KB
testcase_09 AC 1,225 ms
161,548 KB
testcase_10 AC 431 ms
141,056 KB
testcase_11 AC 1,208 ms
161,320 KB
testcase_12 AC 443 ms
142,588 KB
testcase_13 AC 419 ms
142,588 KB
testcase_14 AC 354 ms
130,068 KB
testcase_15 AC 753 ms
155,392 KB
testcase_16 AC 782 ms
144,692 KB
testcase_17 AC 1,252 ms
163,388 KB
testcase_18 AC 1,188 ms
156,644 KB
testcase_19 AC 970 ms
148,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N, M, X=map(int, input().split())
edge=[[] for i in range(N)]
for i in range(M):
  u, v, C, T=map(int, input().split())
  u-=1; v-=1
  edge[u].append((v, C, T))
  edge[v].append((u, C, T))

d=[]
timeMIN=[None for i in range(N)]
heapq.heapify(d)

# 各タプルは (時間, - 残りのお金, 頂点) で入れる
heapq.heappush(d, (0, 0, 0))

while len(d)>0:
  t, mon, v=heapq.heappop(d)
  mon*=-1
  if timeMIN[v]==None: timeMIN[v]=t
  else: continue
  for nv, C, T in edge[v]:
    if timeMIN[nv]!=None: continue
    nt=t+T
    nmon=mon-C
    if nmon<0:
      nt+=(abs(nmon)+X-1)//X
      nmon%=X
    heapq.heappush(d, (nt, -nmon, nv))

print(timeMIN[N-1] if timeMIN[-1]!=None else -1)
0