#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; int N, M; vector U; vector

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