def read_data(): N, M = map(int, input().split()) Us = [int(input()) for i in range(N)] dist = [dict() for i in range(N)] for n in range(N - 1): a, b, c = map(int, input().split()) dist[a][b] = c dist[b][a] = c return N, M, Us, dist def solve(N, M, Us, dist): M2 = M // 2 used = [False] * N dp = [[0] * (M2 + 1) for i in range(N)] dfs(0, Us, dist, dp, used, M2) return max(dp[0][:M2 + 1]) def dfs(v, Us, dist, dp, used, M2): used[v] = True dp[v][0] = Us[v] dpv = dp[v] for u, cost in dist[v].items(): if used[u]: continue dfs(u, Us, dist, dp, used, M2) dpu = dp[u] merge_dp(dpv, dpu, M2, cost) def merge_dp(dpv, dpu, M2, cost): for k in range(M2, cost - 1, -1): dpvk = dpv[k] for i in range(k - cost + 1): dpv0 = dpv[k - i - cost] dpui = dpu[i] if dpv0 and dpui and dpv0 + dpui > dpvk: dpvk = dpv0 + dpui dpv[k] = dpvk N, M, Us, dist = read_data() print(solve(N, M, Us, dist))