n,m = map(int,input().split()) m //= 2 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)) def dfs(v,p): for u,d in g[v]: if u == p: continue dfs(u,v) for i in range(m,d-1,-1): for k in range(i-d+1): dp[v][i] = max(dp[v][i],dp[v][i-k-d] + dp[u][k]) dp = [[U[i]]*(m+1) for i in range(n)] dfs(0,-1) print(max(dp[0]))