#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second typedef long long ll; typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vpii; template bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } void Main() { int N, T; scanf("%d%d", &N, &T); vi U(N); rep(i, N) scanf("%d", &U[i]); vector E(N); rep(i, N-1) { int u, v, w; scanf("%d%d%d", &u, &v, &w); E[u].emplace_back(v, w); E[v].emplace_back(u, w); } function dfs = [&](int cur, int pre) { //_p("dfs(%d,%d)\n", cur,pre); vector subs; forr(nex, E[cur]) { int nev = nex.fst; int nec = nex.snd; if (nev == pre) continue; vpii sub = dfs(nev, cur); forr(s, sub) { //_p("(%d,%d)\n", s.fst, s.snd); s.snd += nec * 2; } subs.push_back(sub); } /* _p("subz:%d\n", SZ(subs)); rep(i, SZ(subs)) { auto &sub = subs[i]; forr(s, sub) _p("%d:%d:(%d,%d)\n",cur,i,s.fst,s.snd); } */ vpii ret; int M = SZ(subs); vi dp(T+1, -1); dp[0] = U[cur]; rep(i, M) { auto sub = subs[i]; rrep(t, T) if (dp[t] >= 0) { forr(s, sub) { if (t + s.snd <= T) amax(dp[t+s.snd], dp[t] + s.fst); } } } rep(t, T+1) if (dp[t] >= 0) { ret.emplace_back(dp[t], t); } //forr(s, ret) _p("%d: (%d,%d)\n",cur,s.fst,s.snd); return ret; }; vpii ret = dfs(0, -1); int ans = 0; forr(s, ret) { ans = max(ans, s.fst); } _p("%d\n", ans); } int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }