/* -*- coding: utf-8 -*- * * 417.cc: No.417 チューリップバブル - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200; const int MAX_M = 2000; /* typedef */ typedef pair pii; typedef vector vpii; typedef map mii; /* global variables */ int us[MAX_N]; vpii nbrs[MAX_N]; /* subroutines */ void rec(int u, int prv, int m, mii &mus) { mus.clear(); mus[0] = us[u]; vpii &nbru = nbrs[u]; for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int &v = vit->first, vc = vit->second * 2; if (v == prv) continue; if (m >= vc) { mii mvs, mts(mus); rec(v, u, m - vc, mvs); for (mii::iterator mitu = mus.begin(); mitu != mus.end(); mitu++) for (mii::iterator mitv = mvs.begin(); mitv != mvs.end(); mitv++) { int c = mitu->first + mitv->first + vc; if (c > m) break; int t = mitu->second + mitv->second; mii::iterator mit = mts.find(c); if (mit == mts.end()) mts[c] = t; else if (mit->second < t) mit->second = t; } swap(mus, mts); } } } /* main */ int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> us[i]; for (int i = 1; i < n; i++) { int a, b, c; cin >> a >> b >> c; nbrs[a].push_back(pii(b, c)); nbrs[b].push_back(pii(a, c)); } mii ms; rec(0, -1, m, ms); int maxt = 0; for (mii::iterator mit = ms.begin(); mit != ms.end(); mit++) { if (maxt < mit->second) maxt = mit->second; //printf("%d,%d\n", mit->first, mit->second); } printf("%d\n", maxt); return 0; }