#include using namespace std; #define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i)) using ll = long long; using namespace std; int N, M; ll dp[201][2010]; ll U[201]; struct edge { int to, cost; edge(int t=0, int c=0) : to(t), cost(c) {} }; vector g[201]; void solve(int v, int p=-1) { dp[v][0] = U[v]; for (auto e : g[v]) { int u = e.to; if (u == p) continue; solve(u, v); for (int i = M; i >= 0; --i) { for (int j = 0; j <= M; ++j) { int tm = i + e.cost + j; if (tm <= M) dp[v][tm] = max(dp[v][tm], dp[v][i] + dp[u][j]); } } } } // // void solve(int v, int tm, int p=-1) { // dp[v][tm] = U[v]; // for (auto e : g[v]) { // if (e.to == p) continue; // int u = e.to; // if (tm + e.cost <= M) { // solve(u, tm + e.cost, v); // } // // for (int t = tm + 1; t <= M-e.cost; ++t) { // if (t + e.cost <= M) { // dp[v][t + e.cost] = max(dp[v][t + e.cost], dp[u][t + e.cost] + dp[v][tm]); // } // else { // dp[v][t] = max(dp[v][t], dp[v][t-1]); // } // } // // } // } int main() { cin >> N >> M; rep(i, N) cin >> U[i]; rep(i, N-1) { int a, b, c; cin >> a >> b >> c; g[a].emplace_back(b, c * 2); g[b].emplace_back(a, c * 2); } solve(0); ll ans = 0; rep(i, M+1) ans = max(ans, dp[0][i]); cout << ans << endl; }