#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int maxn=2e5+9;
i64 dp[maxn][2];
int deg[maxn],mark[maxn];
vector<pair<int,i64>> adj[maxn];
void DFSdp(int u,int pu,int k)
{
i64 sum=0;
vector<pair<i64,i64>> hmm;
for(auto& [v,w]:adj[u])
{
if(v!=pu)
{
DFSdp(v,u,k);
hmm.push_back({dp[v][0],dp[v][1]+w});
sum+=dp[v][1]+w;
}
}
sort(hmm.begin(),hmm.end(),[&](pair<i64,i64> x,pair<i64,i64> y){
return x.first-x.second<y.first-y.second;
});
dp[u][0]=dp[u][1]=sum;
for(int ch=0,i=0;i<hmm.size();++i)
{
if(hmm[i].first<hmm[i].second) sum+=hmm[i].first-hmm[i].second,++ch;
if(ch<k) dp[u][0]=sum;
if(ch<=k) dp[u][1]=sum;
}
}
vector<int> NodeList;
vector<pair<int,i64>> bdj[maxn];
struct Raven
{
multiset<i64> Rachel,Roth;
i64 sumin=0,sumall=0;
void Add(i64 x) {Roth.insert(x);sumall+=x;}
void Calibrate(int k)
{
while(!Rachel.empty() and (Rachel.size()>k or *Rachel.rbegin()>=0))
{
auto it=prev(Rachel.end());
Roth.insert(*it); sumin-=*it;
Rachel.erase(it);
}
while(!Roth.empty() and Rachel.size()<k and *Roth.begin()<0)
{
auto it=Roth.begin();
Rachel.insert(*it); sumin+=*it;
Roth.erase(it);
}
}
void Remove(i64 x)
{
auto it=Rachel.find(x);
if(it==Rachel.end()) Roth.erase(Roth.find(x));
else Rachel.erase(it),sumin-=x;
sumall-=x;
}
};
Raven Yioo[maxn];
void DFSrg(int u,int pu)
{
if(mark[u]) NodeList.push_back(u);
for(auto& [v,w]:adj[u])
{
if(v!=pu)
{
DFSrg(v,u);
if(mark[u]==1)
{
if(mark[v]==1) bdj[u].push_back({v,w});
else Yioo[u].Add(-w);
}
}
else if(mark[u]==1 and mark[v]==0) Yioo[u].Add(-w);
}
}
void DFSdp2(int u,int pu,int k)
{
i64 sum=-Yioo[u].sumall;
for(auto& [v,w]:bdj[u])
{
if(v!=pu)
{
DFSdp2(v,u,k);
Yioo[u].Add(dp[v][0]-dp[v][1]-w);
sum+=dp[v][1]+w;
}
}
Yioo[u].Calibrate(k); dp[u][0]=dp[u][1]=sum+Yioo[u].sumin;
if(Yioo[u].Rachel.size()==k) dp[u][0]-=*Yioo[u].Rachel.rbegin();
}
vector<i64> minimum_closure_costs(int N,vector<int> U,vector<int> V,vector<int> W)
{
vector<i64> res(N,0);
int S=sqrtl(N);
for(int i=1;i<N;++i)
{
res[0]+=W[i-1],++deg[U[i-1]],++deg[V[i-1]];
adj[U[i-1]].push_back({V[i-1],W[i-1]});
adj[V[i-1]].push_back({U[i-1],W[i-1]});
}
for(int k=1;k<=min(S,N-1);++k)
{
DFSdp(0,-1,k);
res[k]=dp[0][1];
}
for(int i=0;i<N;++i)
if(deg[i]>S) mark[i]=1;
DFSrg(0,-1);
for(int k=S+1;k<N;++k)
{
for(int& u:NodeList)
{
if(mark[u]==1)
{
DFSdp2(u,-1,k);
res[k]+=dp[u][1];
}
}
for(int& u:NodeList)
{
if(mark[u]==1)
{
for(auto& [v,w]:bdj[u])
Yioo[u].Remove(dp[v][0]-dp[v][1]-w);
}
}
}
return res;
}
#ifdef Graven
int n; vector<int> u,v,w;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n; u.resize(n); v.resize(n); w.resize(n);
for(int i=1;i<n;++i) cin>>u[i-1]>>v[i-1]>>w[i-1];
vector<i64> res=minimum_closure_costs(n,u,v,w);
for(int i=0;i<n;++i) cout<<res[i]<<" ";
}
#endif
/*
5
0 1 1
0 2 4
0 3 3
2 4 2
-> 10 5 1 0 0
4
0 1 5
2 0 10
0 3 5
-> 20 10 5 0
*/