N,M = map(int,input().split()) U = [int(input()) for _ in range(N)] AB = [list(map(int,input().split())) for _ in range(N-1)] E = [[] for _ in range(N)] for a, b, c in AB: E[a].append((b,c)) E[b].append((a,c)) dp = [[] for _ in range(N)] def dfs(x,p = -1): t1 = [] for y,c in E[x]: t2 = {0:0} if y != p: a = 2 * c b = U[y] dfs(y,x) for c,d in dp[y].items(): ac = a + c bd = b + d if ac <= M: if ac in t2: t2[ac] = max(t2[ac],bd) else: t2[ac] = bd t1.append(t2) tq1 = {0:0} for i in range(len(t1)): tq2 = {} for a,b in t1[i].items(): for c,d in tq1.items(): ac = a+c bd = b+d if ac <= M: if ac in tq2: tq2[ac] = max(tq2[ac],bd) else: tq2[ac] = bd tq1 = tq2 dp[x] = tq1 dfs(0) print(max(dp[0].values()) + U[0])