結果

問題 No.1 道のショートカット
ユーザー rarpipipi
提出日時 2023-12-31 03:33:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 71,768 KB
最終ジャッジ日時 2024-09-27 17:00:43
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

INF=float('inf')
n=int(input())
c=int(input())
v=int(input())

from collections import defaultdict
edge=defaultdict(list)

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()))
for i in range(v):
    si,ti,yi,mi=s[i],t[i],y[i],m[i]
    edge[si].append((ti,yi,mi))

dp=[[] for i in range(n)]
dp[0]=[(0,0)]
for ci in range(n):
    for cy,cm in dp[ci]:
        for ni,ny,nm in edge[ci]:
            if cy+ny<=c:
                for niy,nim in dp[ni]:
                    if niy<cy+ny and nim<cm+nm:
                        break
                else:
                    dp[ni].append((cy+ny,cm+nm))

if dp[-1]:
    print(min([mm for yy,mm in dp[-1]]))
else:
    print(-1)
0