結果

問題 No.1 道のショートカット
ユーザー Hydru
提出日時 2023-01-15 10:48:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 72,704 KB
最終ジャッジ日時 2024-12-27 23:42:17
合計ジャッジ時間 5,219 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

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

S=list(map(lambda x:int(x)-1,input().split()))
T=list(map(lambda x:int(x)-1,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]].append((T[i],Y[i],M[i]))

inf=float("inf")

DP=[[inf]*(C+1) for _ in range(N)]

DP[0][0]=0
for i in range(N-1):
    for u,m,t in G[i]:
        for j in range(C+1):
            if j+m>C:
                break
            DP[u][j+m]=min(DP[u][j+m],DP[i][j]+t)

ans=min(DP[N-1])

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