#include using namespace std; const int MAX_N = 222; const int MAX_M = 2222; int N, M; long long U[MAX_N]; vector> G[MAX_N]; long long dp[MAX_N][MAX_M]; void dfs(int now, int prev) { for (int i = 0; i <= M; i++) { dp[now][i] = U[now]; } for (auto &&el : G[now]) { if (el.first != prev) { dfs(el.first, now); for (int i = M; i >= 0; i--) { for (int j = 0; j <= M; j++) { if (i - j - el.second * 2 < 0) break; dp[now][i] = max(dp[now][i], dp[now][i - j - el.second * 2] + dp[el.first][j]); } } } } } int main() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) { scanf("%lld", U + i); } for (int i = 0; i < N - 1; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); //a--;b--; G[a].emplace_back(make_pair(b, c)); G[b].emplace_back(make_pair(a, c)); } dfs(0, -1); long long ans = 0; for (int i = 0; i <= M; i++) { ans = max(ans, dp[0][i]); } printf("%lld\n", ans); }