#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vector<pair<ll,ii> > edges;
set<int> S[511111];
ii T[511111];
int counteridx[511111];
int cnt;
int lab[100011];

struct DSU
{
	int SS;
	
	struct node
	{
		int p; ll sum;
		int idx;
		set<int> vec;
	};
	vector<node> dsu;
	
	DSU(int n)
	{
		SS = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 1; tmp.idx = i;
			tmp.vec.insert(i);
			dsu.pb(tmp);
		}
	}
	
	void reset(int n)
	{
		dsu.clear();
		SS = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 1; tmp.idx=i;
			tmp.vec.insert(i);
			dsu.pb(tmp);
		}
	}
	
	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}
	
	void merge(int u, int v, bool mode = 0)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(dsu[u].sum<dsu[v].sum) swap(u,v);
		dsu[v].p = u;
		////cerr<<"IDX : "<<v<<' '<<dsu[v].idx<<'\n';
		for(auto it = dsu[v].vec.begin(); it!=dsu[v].vec.end();it++)
		{
			if(!mode) S[dsu[v].idx].insert((*it));
			dsu[u].vec.insert((*it));
		}
		dsu[u].sum += dsu[v].sum;
		if(!mode)
		{
			T[cnt] = mp(dsu[u].idx,dsu[v].idx); //u first, then v
			dsu[u].idx = cnt++;
			counteridx[dsu[u].idx]=u;
		}
	}
	
	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}
	
	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

DSU dsu(1);
void assignlabels(int id, int l, int r)
{
	//cerr<<"SOLVE : "<<id<<' '<<l<<' '<<r<<' '<<T[id].fi<<' '<<T[id].se<<'\n';
	if(T[id].fi==0&&T[id].se==0) 
	{
		lab[id]=l;
		return ;
	}
	int rsiz = S[T[id].se].size();
	int lsiz = S[T[id].fi].size();
	if(lsiz==0)
	{
		int u=counteridx[T[id].fi];
		lsiz=dsu.dsu[u].vec.size();
	}
	////cerr<<lsiz<<' '<<rsiz<<'\n';
	assignlabels(T[id].fi,l,r-rsiz);
	assignlabels(T[id].se,r-rsiz+1,r);
}

class LazySegmentTree {
private:
	int size_;
	vector<long long> v, lazy;
	void update(int a, int b, long long x, int k, int l, int r) {
		push(k, l, r);
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			push(k, l, r);
		}
		else {
			update(a, b, x, k * 2, l, (l + r) >> 1);
			update(a, b, x, k * 2 + 1, (l + r) >> 1, r);
			v[k] = merge(v[k * 2], v[k * 2 + 1]);
		}
	}
	long long query(int a, int b, int k, int l, int r) {
		push(k, l, r);
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return v[k];
		long long lc = query(a, b, k * 2, l, (l + r) >> 1);
		long long rc = query(a, b, k * 2 + 1, (l + r) >> 1, r);
		return merge(lc, rc);
	}
 
public:
	LazySegmentTree() : v(vector<long long>()), lazy(vector<long long>()) {};
	LazySegmentTree(int n) {
		for (size_ = 1; size_ < n;) size_ <<= 1;
		v.resize(size_ * 2);
		lazy.resize(size_ * 2);
	}
	inline void push(int k, int l, int r) {
		if (lazy[k] != 0) {
			v[k] += lazy[k] * (r - l);
			if (r - l > 1) {
				lazy[k * 2] += lazy[k];
				lazy[k * 2 + 1] += lazy[k];
			}
			lazy[k] = 0;
		}
	}
	inline long long merge(long long x, long long y) {
		return x + y;
	}
	inline void update(int l, int r, long long x) {
		update(l, r, x, 1, 0, size_);
	}
	inline long long query(int l, int r) {
		return query(l, r, 1, 0, size_);
	}
};

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	dsu.reset(n);
	if(n==1)
	{
		cout<<0<<'\n'; return 0;
	}
	for(int i=0;i<n-1;i++)
	{
		int u,v,w; cin>>u>>v>>w;
		u--; v--;
		edges.pb(mp(w,mp(u,v)));
	}
	sort(edges.rbegin(),edges.rend());
	cnt = n;
	for(int i=0;i<edges.size();i++)
	{
		int u=edges[i].se.fi; int v=edges[i].se.se;
		if(!dsu.sameset(u,v))
		{
			dsu.merge(u,v);
		}
	}
	assignlabels(dsu.dsu[dsu.rt(0)].idx,0,n-1);
	dsu.reset(n);
	LazySegmentTree ans(n);
	for(int i=0;i<n;i++)
	{
		//cerr<<i<<' '<<lab[i]<<'\n';
	}
	for(int i=0;i<edges.size();i++)
	{
		int u=edges[i].se.fi; int v=edges[i].se.se;
		u=lab[u]; v=lab[v];
		if(!dsu.sameset(u,v))
		{
			u=dsu.rt(u); v=dsu.rt(v);
			ll L = dsu.dsu[u].vec.size(); ll R = dsu.dsu[v].vec.size();
			ll minL = *(dsu.dsu[u].vec.begin()); ll minR = *(dsu.dsu[v].vec.begin());
			//cerr<<L<<' '<<R<<' '<<minL<<' '<<minR<<'\n';
			ans.update(minL, minL + L, ll(edges[i].fi)*R);
			//cerr<<"UPDATE : "<<minL<<' '<<minL+L-1<<' '<<ll(edges[i].fi)*R<<'\n';
			ans.update(minR, minR + R, ll(edges[i].fi)*L); 
			//cerr<<"UPDATE : "<<minR<<' '<<minR+R-1<<' '<<ll(edges[i].fi)*L<<'\n';
			dsu.merge(u,v,1);
			//cerr<<"MERGE : "<<u<<' '<<v<<'\n';
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans.query(lab[i],lab[i]+1)<<'\n';
	}
}	


Measured memory_bytes: 104696