結果

問題 No.1 道のショートカット
ユーザー lloyzlloyz
提出日時 2023-09-27 07:22:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 190 ms / 5,000 ms
コード長 851 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 80,848 KB
最終ジャッジ日時 2023-09-27 07:22:38
合計ジャッジ時間 7,832 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,732 KB
testcase_01 AC 80 ms
71,840 KB
testcase_02 AC 87 ms
71,676 KB
testcase_03 AC 81 ms
71,780 KB
testcase_04 AC 82 ms
71,472 KB
testcase_05 AC 82 ms
71,676 KB
testcase_06 AC 85 ms
71,772 KB
testcase_07 AC 86 ms
71,716 KB
testcase_08 AC 140 ms
79,356 KB
testcase_09 AC 107 ms
78,132 KB
testcase_10 AC 133 ms
79,124 KB
testcase_11 AC 172 ms
79,940 KB
testcase_12 AC 168 ms
80,268 KB
testcase_13 AC 190 ms
80,848 KB
testcase_14 AC 88 ms
76,252 KB
testcase_15 AC 86 ms
76,324 KB
testcase_16 AC 102 ms
77,808 KB
testcase_17 AC 86 ms
76,484 KB
testcase_18 AC 91 ms
76,524 KB
testcase_19 AC 92 ms
76,256 KB
testcase_20 AC 156 ms
78,960 KB
testcase_21 AC 97 ms
77,520 KB
testcase_22 AC 89 ms
77,204 KB
testcase_23 AC 168 ms
79,688 KB
testcase_24 AC 170 ms
79,596 KB
testcase_25 AC 138 ms
79,360 KB
testcase_26 AC 134 ms
78,368 KB
testcase_27 AC 183 ms
80,428 KB
testcase_28 AC 91 ms
76,564 KB
testcase_29 AC 124 ms
78,792 KB
testcase_30 AC 100 ms
77,724 KB
testcase_31 AC 101 ms
77,804 KB
testcase_32 AC 148 ms
79,904 KB
testcase_33 AC 129 ms
78,756 KB
testcase_34 AC 178 ms
79,668 KB
testcase_35 AC 90 ms
77,068 KB
testcase_36 AC 125 ms
78,132 KB
testcase_37 AC 95 ms
77,720 KB
testcase_38 AC 87 ms
76,532 KB
testcase_39 AC 87 ms
76,528 KB
testcase_40 AC 88 ms
77,364 KB
testcase_41 AC 87 ms
71,732 KB
testcase_42 AC 83 ms
71,840 KB
testcase_43 AC 88 ms
76,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappop, heappush

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 = defaultdict(list)
for i in range(v):
    s, t, y, m = S[i], T[i], Y[i], M[i]
    s -= 1
    t -= 1
    G[s].append((t, y, m))

INF = 10**18
DP = [[INF for _ in range(c + 1)] for _ in range(n)]
DP[0][0] = 0
H = [(0, 0, 0)]
while H:
    cp, cc, ct = heappop(H)
    if ct > DP[cp][cc]:
        continue
    for np, dc, dt in G[cp]:
        nc = cc + dc
        nt = ct + dt
        if nc > c:
            continue
        if nt >= DP[np][nc]:
            continue
        DP[np][nc] = nt
        heappush(H, (np, nc, nt))
ans = min(DP[n - 1])
if ans == INF:
    ans = -1
print(ans)
0