結果

問題 No.1 道のショートカット
ユーザー stnkienstnkien
提出日時 2020-06-12 00:56:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 82,848 KB
最終ジャッジ日時 2023-09-27 22:30:13
合計ジャッジ時間 6,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,296 KB
testcase_01 AC 70 ms
71,444 KB
testcase_02 AC 69 ms
71,268 KB
testcase_03 AC 69 ms
71,464 KB
testcase_04 AC 73 ms
71,256 KB
testcase_05 AC 71 ms
71,124 KB
testcase_06 AC 71 ms
71,448 KB
testcase_07 AC 71 ms
71,244 KB
testcase_08 AC 131 ms
78,112 KB
testcase_09 AC 93 ms
76,976 KB
testcase_10 AC 121 ms
78,468 KB
testcase_11 AC 161 ms
79,284 KB
testcase_12 AC 206 ms
81,656 KB
testcase_13 AC 156 ms
79,164 KB
testcase_14 AC 70 ms
71,636 KB
testcase_15 AC 71 ms
71,140 KB
testcase_16 AC 87 ms
77,448 KB
testcase_17 AC 70 ms
71,576 KB
testcase_18 AC 72 ms
71,204 KB
testcase_19 AC 73 ms
71,472 KB
testcase_20 AC 120 ms
78,136 KB
testcase_21 AC 89 ms
76,728 KB
testcase_22 AC 76 ms
75,680 KB
testcase_23 AC 251 ms
82,848 KB
testcase_24 AC 242 ms
82,484 KB
testcase_25 AC 143 ms
78,796 KB
testcase_26 AC 123 ms
78,216 KB
testcase_27 AC 185 ms
80,284 KB
testcase_28 AC 69 ms
71,428 KB
testcase_29 AC 124 ms
78,452 KB
testcase_30 AC 91 ms
76,744 KB
testcase_31 AC 127 ms
78,792 KB
testcase_32 AC 152 ms
78,772 KB
testcase_33 AC 126 ms
78,356 KB
testcase_34 AC 158 ms
79,156 KB
testcase_35 AC 90 ms
76,580 KB
testcase_36 AC 106 ms
78,156 KB
testcase_37 AC 85 ms
76,584 KB
testcase_38 AC 72 ms
71,248 KB
testcase_39 AC 73 ms
71,376 KB
testcase_40 AC 78 ms
76,356 KB
testcase_41 AC 69 ms
71,204 KB
testcase_42 AC 69 ms
71,404 KB
testcase_43 AC 70 ms
71,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
N = int(input())
C = int(input())
V = int(input())
*S, = map(int, input().split())
*T, = map(int, input().split())
*Y, = map(int, input().split())
*M, = map(int, input().split())

G = [[] for _ in [0]*(N+1)]
for s, *t in zip(S, T, Y, M):
    G[s].append(t)

INF = 10**10
D = [[INF]*(C+1) for _ in [0]*(N+1)]
used = set()
q = []
heappush(q, (0, 1, C))

while q:
    dmin = INF
    d, v, c = heappop(q)
    if (v, c) in used:
        continue
    used.add((v, c))
    D[v][c] = d

    for u, y, m in G[v]:
        if (u, c-y) in used or c-y < 0:
            continue
        new_d = d+m
        if new_d < D[u][c-y]:
            heappush(q, (d+m, u, c-y))

ans = min(D[N])
if ans == INF:
    print(-1)
else:
    print(ans)
0