#include #pragma warning(disable:4996) using namespace std; using ll = long long; //http://kmjp.hatenablog.jp/entry/2016/08/27/0930 int N, M; int U[1000]; ll dp[200][1001]; vector>E[200]; void dfs(int p, int c0) { for (int i = 0; i <= M; i++) { dp[c0][i] = U[c0];//dp[親][時間]を親地点の獲得ポイントで初期化 } for (auto e : E[c0]) { if (e.first != p) {//子が親でなければ int c1 = e.first; int cost = e.second; dfs(c0, c1); for (int i = M; i >= 0; i--) { for (int j = 0; j + cost <= i; j++) { dp[c0][i] = max(dp[c0][i], dp[c0][i - (j + cost)] + dp[c1][j]); } } } } } int main() { scanf("%d %d", &N, &M); M /= 2; for (int i = 0; i < N; i++) { scanf("%d", &U[i]); } for (int i = 0; i < N - 1; i++) { int from, to, cost; scanf("%d %d %d", &from, &to, &cost); E[from].push_back(make_pair(to, cost)); E[to].push_back(make_pair(from, cost)); } dfs(-1, 0); printf("%lld\n", *max_element(dp[0], dp[0] + M + 1)); }