結果

問題 No.1 道のショートカット
ユーザー kamiyomokikanukamiyomokikanu
提出日時 2019-08-17 00:13:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 384 ms / 5,000 ms
コード長 1,362 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 9,492 KB
最終ジャッジ日時 2023-09-27 22:21:38
合計ジャッジ時間 3,990 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,716 KB
testcase_01 AC 17 ms
8,840 KB
testcase_02 AC 17 ms
8,668 KB
testcase_03 AC 16 ms
8,676 KB
testcase_04 AC 16 ms
8,716 KB
testcase_05 AC 16 ms
8,696 KB
testcase_06 AC 15 ms
8,704 KB
testcase_07 AC 16 ms
8,672 KB
testcase_08 AC 42 ms
9,048 KB
testcase_09 AC 20 ms
8,872 KB
testcase_10 AC 38 ms
9,068 KB
testcase_11 AC 107 ms
9,104 KB
testcase_12 AC 186 ms
9,492 KB
testcase_13 AC 173 ms
9,328 KB
testcase_14 AC 17 ms
8,712 KB
testcase_15 AC 17 ms
8,668 KB
testcase_16 AC 18 ms
8,876 KB
testcase_17 AC 17 ms
8,668 KB
testcase_18 AC 16 ms
8,752 KB
testcase_19 AC 16 ms
8,720 KB
testcase_20 AC 27 ms
8,688 KB
testcase_21 AC 18 ms
8,708 KB
testcase_22 AC 17 ms
8,784 KB
testcase_23 AC 384 ms
9,024 KB
testcase_24 AC 311 ms
8,908 KB
testcase_25 AC 51 ms
8,744 KB
testcase_26 AC 28 ms
8,688 KB
testcase_27 AC 217 ms
9,128 KB
testcase_28 AC 17 ms
8,740 KB
testcase_29 AC 57 ms
8,924 KB
testcase_30 AC 22 ms
8,704 KB
testcase_31 AC 58 ms
8,820 KB
testcase_32 AC 65 ms
9,000 KB
testcase_33 AC 37 ms
8,884 KB
testcase_34 AC 245 ms
9,132 KB
testcase_35 AC 18 ms
8,804 KB
testcase_36 AC 30 ms
9,004 KB
testcase_37 AC 23 ms
8,852 KB
testcase_38 AC 16 ms
8,656 KB
testcase_39 AC 17 ms
8,740 KB
testcase_40 AC 17 ms
8,884 KB
testcase_41 AC 16 ms
8,764 KB
testcase_42 AC 15 ms
8,792 KB
testcase_43 AC 16 ms
8,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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()))

#print(S)
#print(T)
#print(Y)
#print(M)

p=[]
for i in range(V):
    p.append([S[i],T[i],Y[i],M[i]])

#print (p)

l=[[] for i in range(N+1)]
lw=[[] for i in range(N+1)]
lt=[[] for i in range(N+1)]
for pi in p:
    l[pi[0]].append(pi[1])
    lw[pi[0]].append(pi[2])
    lt[pi[0]].append(pi[3])

#print(l)
#print(lw)
#print(lt)

queue=deque([1])
queue2=deque([0])

data=[-1 for i in range(N+1)]
dp=[[-1 for i in range(C+1)] for j in range(N+1)]
dp[1][0]=0

while len(queue) > 0:
    n=queue.popleft()
    c=queue2.popleft()
    #print (n)
    f=False
    for i in range(len(l[n])):
        nt=l[n][i]
        ntw=lw[n][i]
        ntt=lt[n][i]
        #print(str(nt)+","+str(ntw)+","+str(ntt))
        if dp[n][c]!=-1:
            tw=c+ntw
            tt=dp[n][c]+ntt
            #print(str(tw)+"-"+str(tt))
            if tw>C:continue
            if dp[nt][tw]==-1 or tt<dp[nt][tw]:
                dp[nt][tw]=tt
                queue.append(nt)
                queue2.append(tw)
#print(dp)

ans=-1
for dpi in dp[N]:
    if(dpi!=-1):
        if(ans==-1):
            ans=dpi
        else:
            ans=min(ans,dpi)
#print (dp[N])
print (str(ans))
0