結果

問題 No.1 道のショートカット
ユーザー Yuta123456
提出日時 2020-05-21 19:37:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 413 ms / 5,000 ms
コード長 810 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,752 KB
最終ジャッジ日時 2024-07-20 16:48:27
合計ジャッジ時間 4,269 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

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()))
adjacent_list = [[] for i in range(n+1)]
for i in range(v):
    adjacent_list[s[i]].append([t[i],y[i],m[i]])
ans = 10**9
memo = [[10**9,10**9] for i in range(n+1)]
def dfs(node,cost,time):
    if node == n:
        global ans
        ans = min(ans, time)
    if memo[node][0] < cost and memo[node][1] < time:
        return 
    if memo[node][0] > cost and memo[node][1] > time:
        memo[node] = [cost, time]
    for n_node, n_cost, n_time in adjacent_list[node]:
        if n_cost + cost <= c:
            dfs(n_node,n_cost + cost, time + n_time)
dfs(1,0,0)
if ans == 10**9:
    print(-1)
else:
    print(ans)
0