結果

問題 No.1 道のショートカット
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-01-21 01:12:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 5,000 ms
コード長 1,033 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 78,160 KB
最終ジャッジ日時 2023-09-27 22:25:22
合計ジャッジ時間 6,063 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,696 KB
testcase_01 AC 83 ms
71,268 KB
testcase_02 AC 78 ms
71,692 KB
testcase_03 AC 79 ms
71,696 KB
testcase_04 AC 77 ms
71,824 KB
testcase_05 AC 77 ms
71,468 KB
testcase_06 AC 78 ms
71,576 KB
testcase_07 AC 78 ms
71,464 KB
testcase_08 AC 110 ms
78,160 KB
testcase_09 AC 91 ms
77,812 KB
testcase_10 AC 100 ms
77,824 KB
testcase_11 AC 104 ms
77,824 KB
testcase_12 AC 111 ms
78,056 KB
testcase_13 AC 107 ms
78,072 KB
testcase_14 AC 79 ms
71,640 KB
testcase_15 AC 79 ms
71,864 KB
testcase_16 AC 87 ms
77,164 KB
testcase_17 AC 82 ms
71,536 KB
testcase_18 AC 77 ms
71,692 KB
testcase_19 AC 81 ms
71,660 KB
testcase_20 AC 100 ms
77,752 KB
testcase_21 AC 86 ms
76,828 KB
testcase_22 AC 79 ms
71,636 KB
testcase_23 AC 110 ms
77,960 KB
testcase_24 AC 108 ms
77,912 KB
testcase_25 AC 100 ms
78,032 KB
testcase_26 AC 93 ms
77,588 KB
testcase_27 AC 111 ms
77,848 KB
testcase_28 AC 79 ms
71,328 KB
testcase_29 AC 99 ms
77,752 KB
testcase_30 AC 93 ms
77,860 KB
testcase_31 AC 92 ms
77,572 KB
testcase_32 AC 100 ms
77,984 KB
testcase_33 AC 98 ms
77,660 KB
testcase_34 AC 109 ms
78,088 KB
testcase_35 AC 86 ms
76,988 KB
testcase_36 AC 91 ms
77,696 KB
testcase_37 AC 87 ms
77,544 KB
testcase_38 AC 82 ms
71,536 KB
testcase_39 AC 81 ms
71,472 KB
testcase_40 AC 86 ms
77,460 KB
testcase_41 AC 78 ms
71,476 KB
testcase_42 AC 77 ms
71,684 KB
testcase_43 AC 81 ms
71,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
C = int(input())
V = int(input())

Sori = list(map(int,input().split()))
Tori = list(map(int,input().split()))
Yori = list(map(int,input().split()))
Mori = list(map(int,input().split()))

dic = {}

for i in range(V):

    s = Sori[i]-1
    t = Tori[i]-1

    y = Yori[i]
    m = Mori[i]

    if s not in dic:
        dic[s] = []

    dic[s].append([t,y,m])


lis = [[float("inf")] * (C+1) for i in range(N) ]
lis[0][0] = 0

q = deque([])
q.append([0,0])

while len(q) > 0:

    now = q.popleft()
    np = now[0]
    nc = now[1]

    if np not in dic:
        continue

    for i in dic[np]:

        nexp = i[0]
        nexc = i[1]
        dis = i[2]

        if nc + nexc <= C:

            if lis[nexp][nc+nexc] > lis[np][nc] + dis:
                lis[nexp][nc+nexc] = lis[np][nc] + dis
                q.append([nexp,nc+nexc])

ans = float("inf")
#print (lis[-1])

for i in range(C+1):

    ans = min(ans , lis[-1][i])

if ans == float("inf"):
    print (-1)
else:
    print (ans)
0