結果

問題 No.1 道のショートカット
ユーザー qibqib
提出日時 2022-10-15 18:48:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 748 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 79,624 KB
最終ジャッジ日時 2023-09-09 03:01:05
合計ジャッジ時間 7,008 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,420 KB
testcase_01 AC 76 ms
71,672 KB
testcase_02 AC 75 ms
71,388 KB
testcase_03 AC 77 ms
71,460 KB
testcase_04 AC 76 ms
71,180 KB
testcase_05 AC 76 ms
71,504 KB
testcase_06 AC 76 ms
71,484 KB
testcase_07 AC 77 ms
71,488 KB
testcase_08 AC 124 ms
78,400 KB
testcase_09 AC 101 ms
76,992 KB
testcase_10 AC 120 ms
78,172 KB
testcase_11 AC 136 ms
78,588 KB
testcase_12 AC 164 ms
78,820 KB
testcase_13 AC 153 ms
78,732 KB
testcase_14 AC 80 ms
75,496 KB
testcase_15 AC 80 ms
75,328 KB
testcase_16 AC 94 ms
77,588 KB
testcase_17 AC 79 ms
75,320 KB
testcase_18 AC 82 ms
75,468 KB
testcase_19 AC 80 ms
75,292 KB
testcase_20 AC 125 ms
78,224 KB
testcase_21 AC 94 ms
76,720 KB
testcase_22 AC 82 ms
75,292 KB
testcase_23 AC 150 ms
78,316 KB
testcase_24 AC 157 ms
79,096 KB
testcase_25 AC 132 ms
78,080 KB
testcase_26 AC 119 ms
77,828 KB
testcase_27 AC 161 ms
79,624 KB
testcase_28 AC 78 ms
75,264 KB
testcase_29 AC 116 ms
78,216 KB
testcase_30 AC 88 ms
76,756 KB
testcase_31 AC 96 ms
76,672 KB
testcase_32 AC 125 ms
78,324 KB
testcase_33 AC 116 ms
78,208 KB
testcase_34 AC 146 ms
78,492 KB
testcase_35 AC 81 ms
75,684 KB
testcase_36 AC 111 ms
78,492 KB
testcase_37 AC 87 ms
76,632 KB
testcase_38 AC 80 ms
75,252 KB
testcase_39 AC 82 ms
75,212 KB
testcase_40 AC 82 ms
76,744 KB
testcase_41 AC 78 ms
71,424 KB
testcase_42 AC 77 ms
71,328 KB
testcase_43 AC 79 ms
75,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 1 << 60

import heapq

n = int(input())
c = int(input())

v = int(input())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
y = list(map(int, input().split()))
m = list(map(int, input().split()))

g = [[] for _ in range(n)]
for i in range(v):
  g[s[i] - 1].append((t[i] - 1, y[i], m[i]))

dist = [[INF for _ in range(c + 1)] for _ in range(n)]
dist[0][c] = 0
hp = [(0, 0, c)]
while len(hp) > 0:
  cd, cv, cc = heapq.heappop(hp)
  if cd > dist[cv][cc]:
  	continue
  for nv, cy, cm in g[cv]:
    if cc >= cy and dist[nv][cc - cy] > dist[cv][cc] + cm:
      dist[nv][cc - cy] = dist[cv][cc] + cm
      heapq.heappush(hp, (dist[nv][cc - cy], nv, cc - cy))

ans = min(dist[-1])
if ans < INF:
  print(ans)
else:
	print("-1")
0