#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; struct E{ int to, w; }; int dp[200][2001], M; vector> G; vi U; void f(int u, int p){ dp[u][0] = U[u]; each(e, G[u]){ if(e.to == p)continue; f(e.to, u); for(int m = M-e.w; m >= 0; --m)if(dp[u][m]!=-1){ rep(mm, M - m - e.w + 1){ smax(dp[u][m + e.w + mm], dp[u][m] + dp[e.to][mm]); } } } rep(i, M)smax(dp[u][i + 1], dp[u][i]); } int main(){ int N, a, b, c; cin >> N >> M; G.resize(N); U.resize(N); rep(i, N) scanf("%d", &U[i]); rep(i, N-1){ scanf("%d%d%d", &a, &b, &c); c *= 2; G[a].push_back(E{b,c}); G[b].push_back(E{a,c}); } MEM(dp, -1); f(0, -1); cout << dp[0][M] << endl; }