#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int i=0;i PI; typedef vector VI; const LL MOD = 1000000007LL; int dp[200][2001]; vector G[200]; int U[200]; int N, M; void dfs(int v, int par) { rep(i, M + 1) dp[v][i] = U[v]; rep(i, G[v].size()) { int to = G[v][i].first; int cost = G[v][i].second; if (to == par) continue; dfs(to, v); for (int j = M; j >= 0; j--) { for (int k = 0; k + cost <= j; k++) { dp[v][j] = max(dp[v][j], dp[v][j - (k + cost)] + dp[to][k]); } } } } 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].push_back(MP(B, C * 2)); G[B].push_back(MP(A, C * 2)); } dfs(0, -1); cout << dp[0][M] << endl; }