結果

問題 No.1 道のショートカット
ユーザー mlihua09
提出日時 2020-08-28 13:00:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 744 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-07-20 16:51:45
合計ジャッジ時間 3,858 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #


N = int(input())

C = int(input())

V = [[] for i in range(N)]

_ = input()

from collections import deque

for s, t, y, m in zip(map(int, input().split()), map(int, input().split()), map(int, input().split()), map(int, input().split())):
    
    V[s - 1] += [[t - 1, y, m]]
    
que = deque([0, 0])

dp = [[10 ** 9] * (C + 1) for i in range(N)]

dp[0][0] = 0

while que:
    
    q1, q2 = que.popleft(), que.popleft()
    
    q3 = dp[q1][q2]
    
    for v, y, m in V[q1]:
        
        if q2 + y <= C and dp[v][q2 + y] > q3 + m:
            
            dp[v][q2 + y] = q3 + m
            
            que.extend([v, q2 + y])
            
ans = min(dp[-1])

if ans == 10 ** 9:
    
    print(-1)
    
else:
    
    print(ans)
        
0