#include #define int long long using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define INF (1ll<<60) typedef pair pii; #define FI first #define SE second #define all(s) s.begin(),s.end() #define RREP(i,n) for(int i=(n)-1;i>=0;--i) int N, M; int U[210]; vector G[210]; int dp[210][2010]; void dfs(int i, int par) { dp[i][0] = U[i]; for (auto p : G[i]) { if (p.FI != par) { dfs(p.FI, i); int j = p.FI; int c = p.SE; RREP(ii,M+1) { rep(jj,M+1) { int t = ii + 2 * c + jj; if (t <= M) dp[i][t] = max(dp[i][t], dp[i][ii] + dp[j][jj]); } } } } } signed main() { cin >> N >> M; rep(i,N) { cin >> U[i]; } rep(i,N-1) { int a, b, c; cin >> a >> b >> c; G[a].push_back(pii(b, c)); G[b].push_back(pii(a, c)); } dfs(0, -1); int ans = 0; rep(i,M+1) { ans = max(ans, dp[0][i]); } cout << ans << endl; }