#include #include #include #include #include using namespace std; struct Edge { int to; int cost; Edge(int to, int cost): to(to), cost(cost) {} }; int main() { int n, m; cin >> n >> m; vector points(n); for(auto &&x: points) cin >> x; vector> edges(n); for (int i=0; i> from >> to >> cost; edges[from].push_back(Edge(to, cost)); edges[to].push_back(Edge(from, cost)); } vector> memo(n, vector(m+1, 0)); function dfs = [&](int cur, int prev) -> void { for (int i=0; i=0; i--) { for (int j=0; j<=i+edge.cost*2; j++) { if (i-(j+edge.cost*2) >= 0) memo[cur][i] = max( memo[cur][i], memo[cur][i-(j+edge.cost*2)] + memo[edge.to][j]); } } } }; dfs(0, -1); cout << *max_element(memo[0].begin(), memo[0].end()) << endl; }