#include using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for(int i=0; ibool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b; vector

G[210]; ll N, M; void dfs(int v, int par, auto& dp, auto& U){ dp[v][0] = U[v]; for(auto& [nv, cost] : G[v]) { if(par == nv) continue; dfs(nv, v, dp, U); for(int m0 = M-1; m0 >= 0; m0--){ for(int m1 = M-1; m1 >= 0; m1--){ auto nm = m0 + m1 + 2*cost; if(nm <= M) chmax(dp[v][nm], dp[v][m0] + dp[nv][m1]); } } } } int main(){ cin >> N >> M; vector U(N); for(auto& u : U) cin >> u; REP(i,N-1){ ll a, b, c; cin >> a >> b >> c; G[a].push_back(P(b, c)); G[b].push_back(P(a, c)); } vector> dp(N, vector(M+1, 0)); dfs(0, -1, dp, U); ll ans = 0; REP(m,M+1) chmax(ans, dp[0][m]); cout << ans << endl; return 0; }