import sys sys.setrecursionlimit(10**5) N, M = map(int, input().split()) U = [int(input()) for _ in range(N)] tree = [[] for _ in range(N)] for _ in range(N-1): a, b, c = map(int, input().split()) tree[a].append((b, c)) tree[b].append((a, c)) # 使用した時間を入れる dp = [[U[i]] * (M + 1) for i in range(N)] def dfs(v, p=-1): for nv, nw in tree[v]: if nv == p: continue dfs(nv, v) for m1 in range(M, -1, -1): for m2 in range(M-m1+1): t = m1 + 2*nw + m2 if t <= M: dp[v][t] = max(dp[v][t], dp[v][m1] + dp[nv][m2]) dfs(0) print(max(dp[0]))