#include #include #include #include #define dst first #define time second using namespace std; typedef pair Edge; const int NODE = 205; const int TIME = 1005; int nNode, limit; int val[NODE]; vector adj[NODE]; void read() { for (int i = 0; i < NODE; ++i) adj[i].clear(); cin >> nNode >> limit; for (int i = 0; i < nNode; ++i) cin >> val[i]; for (int i = 0; i < nNode - 1; ++i) { int s, t, c; cin >> s >> t >> c; adj[s].push_back(Edge(t, c)); adj[t].push_back(Edge(s, c)); } limit /= 2; } void rec(int prev, int curr, int dp[NODE][TIME]) { for (int i = 0; i < adj[curr].size(); ++i) { Edge &e = adj[curr][i]; if (e.dst == prev) continue; rec(curr, e.dst, dp); } dp[curr][0] = val[curr]; for (int i = 0; i < adj[curr].size(); ++i) { Edge &e = adj[curr][i]; if (e.dst == prev) continue; for (int curUsedTime = limit; curUsedTime >= 0; --curUsedTime) { if (dp[curr][curUsedTime] == -1) continue; for (int nexUsedTime = limit - curUsedTime - e.time; nexUsedTime >= 0; --nexUsedTime) { if (dp[e.dst][nexUsedTime] == -1) continue; int nextValue = dp[curr][curUsedTime] + dp[e.dst][nexUsedTime]; dp[curr][curUsedTime + nexUsedTime + e.time] = max(dp[curr][curUsedTime + nexUsedTime + e.time], nextValue); } } } } void work() { // dp[node][used time] := maximum value static int dp[NODE][TIME]; memset(dp, -1, sizeof(dp)); rec(-1, 0, dp); cout << *max_element(dp[0], dp[0] + limit + 1) << endl; } int main() { read(); work(); return 0; }