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)) dp = [[U[i]]*(M+1) for i in range(N)] def dfs(x, par=-1): for nx, t in G[x]: if nx==par: continue dfs(nx, x) for m in range(M+1)[::-1]: for mm in range(M-m+1-t): T = m+mm+t dp[x][T] = max(dp[x][T], dp[x][m]+dp[nx][mm]) dfs(0) print(max(dp[0]))