from itertools import count n, m = map(int, input().split()) u = [int(input()) for _ in range(n)] g = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = map(int, input().split()) g[a].append((b, c)) g[b].append((a, c)) dp = [[0] * (m + 1) for _ in range(n)] def dfs(crr, prv): for nxt, _ in g[crr]: if nxt != prv: dfs(nxt, crr) for nxt, t in g[crr]: for i in range(m, -1, -1): for j in count(0): if i < 2 * t + j: break dp[crr][i] = max(dp[crr][i], dp[crr][i - (2 * t + j)] + dp[nxt][j]) for i in range(m + 1): dp[crr][i] += u[crr] dfs(0, n) print(dp[0][m])