#include <bits/stdc++.h>
using namespace std;
#define int LL
using LL=long long;
constexpr int N(1e6);
int n;
int fa[N+5],dep[N+5];
int L[N+5],R[N+5],fz[N+5];
bool les(int x,int y) { return dep[fz[x]]>dep[fz[y]]; }
int Max(int x,int y) { return les(y,x)?x:y; }
void chkMax(int &x,int y) { x=Max(x,y); }
struct RMQ {
int bs;
int st[20][N/20+5];
int bl[N+5],p[N+5];
int pre[N+5],suf[N+5];
int F[N+5],S[N+5];
void init() {
bs=log2(n)*1.5;
for (int i{1};i<=n;++i) {
bl[i]=(i-1)/bs+1;
if (bl[i-1]!=bl[i]) p[i]=0;
else p[i]=p[i-1]+1;
}
for (int i{1};i<=n;++i)
if (bl[i]!=bl[i-1]) st[0][bl[i]]=i;
else chkMax(st[0][bl[i]],i);
for (int i{1};i<=__lg(bl[n]);++i)
for (int j{1};j+(1<<i)-1<=bl[n];++j)
st[i][j]=Max(st[i-1][j],st[i-1][j+(1<<i-1)]);
for (int i{1};i<=n;++i) {
if (bl[i]!=bl[i-1]) pre[i]=i;
else pre[i]=Max(pre[i-1],i);
}
for (int i{n};i>=1;--i) {
if (bl[i]!=bl[i+1]) suf[i]=i;
else suf[i]=Max(suf[i+1],i);
}
for (int i{1};i<=n;++i) {
if (bl[i]!=bl[i-1]) *S=0;
else F[i]=F[i-1];
while (*S>0&&les(S[*S],i)) F[i]^=1<<p[S[(*S)--]];
S[++*S]=i;F[i]|=(1<<p[i]);
}
}
int ask(int l,int r) {
int L{bl[l]},R{bl[r]};
if (L!=R) {
int ans{Max(suf[l],pre[r])};
if (L-R>1) {
int z{__lg(R-L-1)};
ans=Max(ans,Max(st[z][L+1],st[z][R-(1<<z)]));
}
return ans;
} else {
return l+__builtin_ctz(F[r]>>p[l]);
}
}
} A;
// tree basic op start
int LCA(int u,int v) {
if (u==v) return u;
u=L[u];v=L[v];
if (u>v) swap(u,v);
return fa[fz[A.ask(u+1,v)]];
}
LL d[N+5];
vector<pair<int,int>> e[N+5];
int lb[N+5];
LL dis(int u,int v) { return d[u]+d[v]-2*d[LCA(u,v)]; }
void init(int u,int fa) {
::fa[u]=fa;
dep[u]=dep[fa]+1;
static int lda{0};
L[u]=++lda;
fz[lda]=u;
int p{fa},q{lb[fa]},r{lb[q]};
lb[u]=(dep[lb[p]]-dep[lb[q]]!=dep[lb[q]]-dep[lb[r]]?p:r);
for (auto [v,w]:e[u])
if (v!=fa) {
d[v]=d[u]+w;
init(v,u);
}
R[u]=lda;
}
int jmp(int u,int k) {
k=dep[u]-k;
while (dep[u]>k) {
if (dep[lb[u]]<k) u=fa[u];
else u=lb[u];
}
return u;
}
bool son(int u,int v) { return L[u]<=L[v]&&L[v]<=R[u]; }
int jump(int a,int b) { return son(a,b)?jmp(b,dep[b]-dep[a]-1):fa[a]; }
// tree basic op end
struct fenwick {
int t[N+5];
void add(int x) {
for (;x<=n;x+=x&-x) ++t[x];
}
int qry(int u) {
int l{L[u]-1},r{R[u]},ans{0};
while (r>l) ans+=t[r],r&=r-1;
while (l>r) ans-=t[l],l&=l-1;
return ans;
}
} T;
struct centroid {
int cnt;
set<int> dots;
int getwt(int v) { return son(cnt,v)?T.qry(jump(cnt,v)):dots.size()-T.qry(cnt); }
int nxt(int p) {
auto it{dots.lower_bound(p)};
if (it==dots.end()) return n+1;
return *it;
}
int pre(int p) {
auto it{dots.upper_bound(p)};
if (it==dots.begin()) return 0;
return *prev(it);
}
int move(int v) {
if (son(cnt,v)) {
int a{jump(cnt,v)};
return LCA(fz[nxt(L[a])],fz[pre(R[a])]);
}
int l{L[cnt]},r{R[cnt]};
int x{v};
for (auto y:{nxt(1),pre(l-1),nxt(r+1),pre(n)}) {
if (y==0||y==n+1||l<=y&&y<=r) continue;
x=LCA(x,fz[y])^LCA(x,cnt)^LCA(fz[y],cnt);
}
return x;
}
void add(int v) {
dots.insert(L[v]);
T.add(L[v]);
if (v==cnt) return;
int wt{getwt(v)};
if (2*wt<=dots.size()) return;
int to{move(v)};
cnt=to;
}
} C;
using P=array<int,2>;
P operator+(const P &a,const P &b) {
if (a[0]==-1) return b;
if (b[0]==-1) return a;
auto [x,y]=a;
LL xy{dis(x,y)};
for (auto z:b) {
LL xz{dis(x,z)},yz{dis(y,z)},mx{max({xy,xz,yz})};
if (mx==xz) y=z,xy=xz;
else if (mx==yz) x=z,xy=yz;
}
return {x,y};
}
struct segtree {
P t[N<<1];
void build() {
for (int i{1};i<=n;++i) t[i+n-1]={i,i};
for (int i{n-1};i>=1;--i)
t[i]=t[i<<1]+t[i<<1|1];
}
void mod(int x) {
t[x+=n-1]={-1,-1};
while (x>>=1) t[x]=t[x<<1]+t[x<<1|1];
}
} S;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n;
for (int i{1};i<n;++i) {
int u,v,w;cin>>u>>v>>w;
e[u].emplace_back(v,w);
e[v].emplace_back(u,w);
}
init(1,0);
A.init();C.cnt=1;S.build();
LL ans{0};
for (int i{1};i<=n;++i) {
int cnt{C.cnt};
auto [a,b]{S.t[1]};
LL xa{dis(a,cnt)},xb{dis(b,cnt)};
if (xa<xb) a=b,xa=xb;
S.mod(a);C.add(a);
ans+=xa-dis(cnt,C.cnt);
if (~i&1) cout<<ans<<" ";
}
return 0;
}