#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) long long dp[200][1001]; int n, m; int U[200]; vector > edge[200]; long long f(int u,int t,int par) { if (dp[u][t] != -1)return dp[u][t]; dp[u][0] = U[u]; for (auto p : edge[u]) { if (par == p.first)continue; for (int i = t - p.second; i >= 0; i--) { if(dp[u][i]!=-1)dp[u][i + p.second] = max(dp[u][i + p.second], dp[u][i] + f(p.first, t-i-p.second, u)); } } for (int i = 1; i <= t; i++)dp[u][i] = max(dp[u][i], dp[u][i - 1]); return dp[u][t]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; m /= 2; rep(i, n)cin >> U[i]; rep(i,n-1) { int a, b, c; cin >> a >> b >> c; edge[a].emplace_back(b, c); edge[b].emplace_back(a, c); } memset(dp, -1, sizeof(dp)); cout << f(0, m, -1) << endl; return 0; }