#include using namespace std; #include using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n,k;cin>>n>>k; vc v(n,vc(0)); rep(i,n-1){ int a,b,c;cin>>a>>b>>c; a--;b--; v[a].pb({b,c}); v[b].pb({a,c}); } int ans=0,ansx=0; vcx; auto f=[&](auto f,int a,int p)->int{ int res=0; if(v[a].size()==1)res=1; for(auto [au,c]:v[a])if(au!=p){ int t=f(f,au,a); x.pb({c,c*t}); ansx+=c*t; res+=t; } return res; }; f(f,0,-1); vcdp(k+1,0); for(auto [a,b]:x){ auto pre=dp; rep(i,k)if(i+a<=k)dp[i+a]=max(dp[i+a],pre[i]+b); } rep(i,k+1)ans=max(ans,dp[i]); cout<