#include #define rep(i, n) for (int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() #define PRINT(v) for (auto x : (v)) cout <>; using mat = vector>; const ll MOD = 1000000007; const ll INF = 10000000000000000; const int inf = 1001001001; vector x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1}; vector y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1}; template inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;} template inline bool chmax(T& a, T b){if (a inline T powerM(T a,T b){if (b==0) return 1; T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; } template inline T power(T a,T b,T m){ if (b==0) return 1; T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; } template inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);} template inline T lcm(T a, T b){return a / gcd(a,b) * b;} // ax+by=gcd(a,b)を解く template inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;} void hey(){ cout <<"hey" < struct edge { int to; T cost;}; int N,M; vector U; vector>> G; vector>> dp; void input(){ cin >>N >>M; U.assign(N, 0); rep(i, N) cin >>U[i]; G.assign(N, vector>()); rep(i, N-1){ int a,b,c; cin >>a >>b >>c; G[a].push_back({b, c}); G[b].push_back({a, c}); } dp.assign(N, vector>(2, vector(M+1))); // dp[i][j] := 頂点iからその部分木へ行って戻ってきて、時間jで取ってこれる税収の最大値 } void dfs(int v, int p){ for (auto pe : G[v]){ int nv = pe.to; if (nv == p) continue; dfs(nv, v); } // 子の情報は全てdpに入っているとする dp[v][0][0] = U[v]; dp[v][1][0] = U[v]; // 時間0なら自分のやつは取って来れる for (auto pe : G[v]){ int nv = pe.to; if (nv == p) continue; // dp[nv][j]を見ていく感じ // 後ろから見ていかないと更新が被りそう for (int j=M-pe.cost*2; j>=0; j--){ int i = j + pe.cost * 2; for (int k=M-i; k>=0; k--){ chmax(dp[v][1][k+j+pe.cost*2], dp[v][0][k] + dp[nv][0][j]); } } dp[v][0] = dp[v][1]; } } int main() { input(); dfs(0, -1); ll res = 0; for (int i=0; i<=M; i++) chmax(res, dp[0][0][i]); cout <