#include using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define all(x) (x).begin(),(x).end() #define foreach(u,v) for(auto (u) : (v)) #define pb push_back #define mp make_pair #define mt make_tuple typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vvi; typedef pair pll; typedef vector vl; const int inf = 1e9; const ll linf = 1LL<<60; const ll mod = 1e9 + 7; const double eps = 1e-9; /*{ dp[i][j] iを根とする部分木で コストjの ときの最大値 }*/ int n, m; int u[200]; vector g[200]; ll dp[200][2000]; void dfs(int x, int par = -1) { dp[x][0] = u[x]; for(auto e : g[x]){ if(e.first == par) continue; dfs(e.first, x); for(int i = m; i >= 0; i--){ rep(j, m+1){ if(i+j+e.second <= m){ dp[x][i+j+e.second] = max(dp[x][i+j+e.second], dp[x][i]+dp[e.first][j]); } } } } } int main() { cin >> n >> m; rep(i, n) cin >> u[i]; rep(i, n-1){ int x, y, c; cin >> x >> y >> c; g[x].pb(mp(y, c)); g[y].pb(mp(x, c)); } m /= 2; dfs(0); ll ans = 0; rep(i, m+1){ ans = max(ans, dp[0][i]); } cout << ans << endl; /* rep(i, n){ rep(j, m+1){ cout << dp[i][j] << " "; } cout << endl; } */ return 0; }