#include template inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair #define PiP pair> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; struct edge{ ll to, cost; }; vector cnt(110); vector

vec; void dfs(const vector> &G, int v, int p){ int ans = 0; for(auto nv : G[v]){ if(nv.to == p)continue; dfs(G, nv.to, v); ans += cnt[nv.to]; vec.push_back({nv.cost * cnt[nv.to], nv.cost}); } cnt[v] = ans; if(ans == 0)cnt[v]++; } int main() { int n, k; cin >> n >> k; assert(n >= 2); assert(n <= 100); assert(k >= 1); assert(k <= 100000); vector> G(n); rep(i, n-1){ ll a, b, c; cin >> a >> b >> c; assert(a >= 1); assert(a <= n); assert(b >= 1); assert(b <= n); assert(c >= 1); assert(c <= k); a--; b--; G[a].push_back({b, c}); G[b].push_back({a, c}); } dfs(G, 0, -1); vector> dp(n, vector(k+1, 0)); ll ans = 0; rep(i, n-1){ ans += vec[i].first; rep(j, k+1){ dp[i+1][j] = dp[i][j]; if(j-vec[i].second >= 0){ chmax(dp[i+1][j], dp[i][j-vec[i].second] + vec[i].first); } } } cout << ans + dp[n-1][k] << endl; }