#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int maxn=2e5+9;
vector<pair<int,i64>> adj[maxn],bdj[maxn];
i64 dp[maxn][2];
struct Raven
{
multiset<i64> Rachel,Roth;
i64 sumin=0,sumall=0;
inline 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);
}
}
inline void Add(i64 x) {Roth.insert(x);sumall+=x;}
inline 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];
int par[maxn],deg[maxn],depth[maxn];
int mark[maxn],mark2[maxn];
vector<int> degl[maxn];
void D1(int u,int pu,int d)
{
depth[u]=d; par[u]=pu;
for(auto& [v,w]:adj[u])
if(v!=pu) D1(v,u,d+1);
}
void D2(int u,int k)
{
if(k==4) cout<<u<<endl;
i64 sum=-Yioo[u].sumall; mark2[u]=k;
for(auto& [v,w]:bdj[u])
{
if(v!=par[u])
{
D2(v,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();
for(auto& [v,w]:bdj[u]) {if(v!=par[u]) Yioo[u].Remove(dp[v][0]-dp[v][1]-w);}
}
vector<i64> minimum_closure_costs(int N,vector<int> U,vector<int> V,vector<int> W)
{
vector<i64> res(N,0);
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 i=0;i<N;++i) degl[deg[i]-1].push_back(i);
set<pair<int,int>> NodeList;
fill(mark2,mark2+N,N); D1(0,-1,0);
for(int k=N-1;k>0;--k)
{
for(int& u:degl[k])
{
for(auto& [v,w]:adj[u])
{
if(mark[v])
{
Yioo[v].Remove(-w);
if(v==par[u]) bdj[v].push_back({u,w});
else bdj[u].push_back({v,w});
}
else Yioo[u].Add(-w);
}
mark[u]=1; NodeList.insert({depth[u],u});
}
if(k<=10)
{
cout<<NodeList.size()<<'\n';
for(int j=0;j<N;++j) cout<<mark2[j]<<" ";
cout<<endl;
}
/*
for(auto& [d,u]:NodeList)
if(mark2[u]!=k) D2(u,k),res[k]+=dp[u][1];
*/
for(auto& [d,u]:NodeList)
{
if(mark2[u]!=k)
{
D2(u,k),res[k]+=dp[u][1];
if(k<=10) cout<<u<<": "<<dp[u][1]<<endl;
}
}
if(k<=10) cout<<endl;
}
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
10
0 1 1
0 2 1
0 3 1
1 4 1
1 5 1
2 6 1
2 7 1
3 8 1
3 9 1
-> 9 6 3 0 0 0 0 0 0 0
10
0 1 1
0 2 1
2 4 1
2 3 1
3 5 1
3 6 1
5 7 1
2 8 1
2 9 1
-> 9 5 3 2 1 0 0 0 0 0
*/