#include using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair #define LP pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() template void chmax(T& a, T b) { a = max(a, b); }; template void chmin(T& a, T b) { a = min(a, b); }; int n, m; vector u(210); vector dp(210, vector(2005)); struct Edge { int to, c; Edge(int to, int c) : to(to), c(c) {} }; vector g[210]; void dfs(int v, int p = -1) { dp[v][0] = u[v]; for (auto e : g[v]) { int nv = e.to, c = e.c; if (nv == p) continue; dfs(nv, v); for (int i = m; i >= 0; i--) { for (int j = m; j >= 0; j--) { if (i+j+2*c <= m) { chmax(dp[v][i+j+2*c],dp[v][i]+dp[nv][j]); } } } } } int main() { cin >> n >> m; rep(i,n) cin >> u[i]; rep(i,n-1) { int a, b, c; cin >> a >> b >> c; g[a].pb(Edge(b,c)); g[b].pb(Edge(a,c)); } dfs(0); int ans = 0; rep(i,m+1) chmax(ans, dp[0][i]); cout << ans << endl; return 0; }