#include<bits/stdc++.h>
#define cmin(a,b)(a>(b)?a=(b),1:0)
#define cmax(a,b)(a<(b)?a=(b),1:0)
#define dmin(a,b)((a)<(b)?(a):(b))
#define dmax(a,b)((a)>(b)?(a):(b))
namespace io{
	int F(){
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'
			&&(ch<'0'||ch>'9'));
			ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'
		&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
int fa[222222],siz[222222],pno,f[222222];
long long add[222222];

int gf(int u){
	if(fa[u]==u)return u;
	return fa[u]=gf(fa[u]);
}

struct edg{
	int x,y,l;
}ed[555555];

bool operator <(const edg &x,const edg &y)
{
	return x.l>y.l;
}

int main(){
	int n=io::F(),m=n-1;
	for(register int i=1;i<=m;++i)
		ed[i]=(edg){io::F(),io::F(),io::F()};
	std::sort(ed+1,ed+m+1);
	pno=n;
	for(register int i=1;i<=n;++i)
		fa[i]=i,siz[i]=1;
	for(register int i=1;i<=m;++i){
		int t1=gf(ed[i].x),t2=gf(ed[i].y);
		if(t1==t2)continue;
		add[t1]=siz[t2]*(long long)ed[i].l;
		add[t2]=siz[t1]*(long long)ed[i].l;
		f[t1]=f[t2]=fa[t1]=fa[t2]=++pno;
		siz[pno]=siz[t1]+siz[t2];
		fa[pno]=pno;
	}
	for(register int i=pno-1;i;--i)
		add[i]+=add[f[i]];
	for(register int i=1;i<=n;++i)
		printf("%lld\n",add[i]);
	return 0;
}