n, m = map(int, input().split()) u_ls = [int(input()) for i in range(n)] c_ls = [set() for i in range(n)] for i in range(n - 1): a, b, c = map(int, input().split()) c_ls[a].add((b, c)) c_ls[b].add((a, c)) memo = [[-1] * (m // 2 + 1) for i in range(n)] def solve(pos, parent, max_m): memo[pos][0] = u_ls[pos] for next_pos, cost in c_ls[pos]: if next_pos == parent: continue next_max_m = max_m - cost solve(next_pos, pos, next_max_m) memo_pos = memo[pos][:] for pos_m in range(next_max_m + 1): if memo_pos[pos_m] < 0: continue for next_m in range(next_max_m - pos_m + 1): if memo[next_pos][next_m] < 0: continue sum_m = pos_m + next_m + cost memo[pos][sum_m] = max(memo_pos[pos_m] + memo[next_pos][next_m], memo[pos][sum_m]) solve(0, -1, m // 2) print(max(memo[0]))