#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, u, v, c; cin >> n >> m; vector a(n); vector>> g(n); vector> dp(n); for(auto &&v:a)cin >> v; for(int i = 1; i < n; i++){ cin >> u >> v >> c; g[u].emplace_back(v, c); g[v].emplace_back(u, c); } m /= 2; function dfs = [&](int v, int p, int d){ vector &temp = dp[v]; temp = {a[v]}; int u, c; for(auto &&pa:g[v]){ tie(u, c) = pa; if(u == p || c > d)continue; dfs(u, v, d - c); vector &temp2 = dp[u]; vector ndp(min(d + 1, int(temp.size() + temp2.size()) + c - 1)); for(int i = 0; i < temp.size(); i++){ ndp[i] = max(ndp[i], temp[i]); for(int j = 0; j < temp2.size() && i + j + c <= d; j++){ ndp[i + j + c] = max(ndp[i + j + c], temp[i] + temp2[j]); } } swap(temp, ndp); } }; dfs(0, -1, m); cout << *max_element(dp[0].begin(), dp[0].end()) << '\n'; }