#include <bits/stdc++.h>
#define FIO "race"
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 200010
using namespace std;
typedef long long ll;
struct edge{int a,b,c;bool operator <(const edge& t)const{return c>t.c;};}e[N];
int n,cnt,fa[N],siz[N],v[N],G[N][2];
ll ans[N];
inline int find(int x){while(x^fa[x])x=fa[x]=fa[fa[x]];return x;}
inline void dfs(int x,ll t){
	if(x<=n){ans[x]=t;return;}
	dfs(G[x][0],t+1ll*v[x]*siz[G[x][1]]),dfs(G[x][1],t+1ll*v[x]*siz[G[x][0]]);
}
int main(){
	cin>>n,cnt=n;
	for(int i=1;i<=n;i++)fa[i]=i,siz[i]=1;
	for(int i=1;i<n;i++)scanf("%d%d%d",&e[i].a,&e[i].b,&e[i].c);
	sort(e+1,e+n);
	for(int i=1;i<n;i++){
		int x=find(e[i].a),y=find(e[i].b);
		cnt++,fa[cnt]=cnt,v[cnt]=e[i].c,siz[cnt]=siz[x]+siz[y],fa[x]=fa[y]=cnt;
		G[cnt][0]=x,G[cnt][1]=y;
	}
	dfs(cnt,0);
	for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
}