#include using namespace std; vector U; struct Edge{ int to,w; Edge(int a,int b){ to = a; w = b; } Edge(){} }; vector> G; vector>> memo; long long DFS(int v,int a,int t,int p = -1){ if(a<0) return 0; if(G[v][a].to==p) return DFS(v,a-1,t,p); if(memo[v][a][t/2]!=-1) return memo[v][a][t/2]; long long res = DFS(v,a-1,t,p); for(int j = 0;j <= (t-2*G[v][a].w);j+=2){ res = max(res,DFS(v,a-1,t-2*G[v][a].w-j,p)+DFS(G[v][a].to,(int)G[G[v][a].to].size()-1,j,v)+U[G[v][a].to]); } memo[v][a][t/2] = res; return res; } int main(){ int N,M; cin >> N >> M; if(M%2) M--; U.assign(N,0); for(int i = 0;i < N;i++) cin >> U[i]; G.assign(N,vector(0)); for(int i = 0;i < N-1;i++){ int A,B,C; cin >> A >> B >> C; G[A].push_back(Edge(B,C)); G[B].push_back(Edge(A,C)); } memo.assign(N,vector>(0)); for(int i = 0;i < N;i++) memo[i].assign(G[i].size(),vector(M/2+1,-1)); cout << DFS(0,(int)G[0].size()-1,M)+U[0] << endl; }