#include #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; typedef tuple t3; typedef tuple t4; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) template void chmax(T& reference, T value) { reference = max(reference, value); } template void chmaxmap(map& m, T key, T value) { if (m.count(key)) { chmax(m[key], value); } else { m[key] = value; } } template void chmin(T& reference, T value) { reference = min(reference, value); } int main() { int n, m; cin >> n >> m; vector us(n); rep(i, n) cin >> us[i]; vector> g(n); 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, -1)); //dp[i][j]...iの村でm時間消費して得られる税収の最大値 function dfs = [&](int current, int parent) { dp[current][0] = 0; for (auto nx : g[current]) { if (nx.first == parent) continue; dfs(nx.first, current); ll time = nx.second * 2; for (int ij = m - time; ij >= 0; ij--) { for (int j = 0; j <= ij; j++) { int i = ij - j; if (dp[nx.first][j] == -1) continue; if (dp[current][i] == -1) continue; ll cost = dp[current][i] + dp[nx.first][j]; chmax(dp[current][ij + time], cost); } } } for (int i = 0; i <= m; i++) { if (dp[current][i] == -1) continue; dp[current][i] += us[current]; } }; dfs(0, -1); ll ans = 0; rep(i, m + 1) { chmax(ans, dp[0][i]); } cout << ans << endl; return 0; }