#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ int n, m; cin >> n >> m; vector U(n); rep(i,n) cin >> U[i]; vector> g(n); rep(i,n-1) { int a, b, c; cin >> a >> b >> c; g[a].emplace_back(make_pair(b, c)); g[b].emplace_back(make_pair(a, c)); } vector> dp(n, vector(m+1,0)); auto dfs = [&](auto& f, int p, int u)->void{ dp[u][0] = U[u]; for (auto e : g[u]) { if (e.first == p) continue; int v = e.first, cost = e.second; f(f, u, v); for (int i = m; i >= 0; i--) { for (int j = 0; j <= m; j++) { int t = i + cost * 2 + j; if (t <= m) dp[u][t] = max(dp[u][t], dp[u][i] + dp[v][j]); } } } }; dfs(dfs, -1, 0); ll res = 0; rep(i,m+1) res = max(res, dp[0][i]); cout << res << endl; return 0; }