// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



#define pb push_back

#define fi first

#define se second



const int N = 1e5 + 1;



typedef pair<int,int> ii;

int n;

int child[N] , vis[N] , d[N] ;

long long ans[N] , tcdall[N] , tcd[N];

vector<ii> adj[N];

vector<int> all , vi[N];



void dfs(int u,int pa){

	child[u] = 1;

	for(int i = 0 ; i < adj[u].size() ; ++ i){

		int v = adj[u][i].fi;

		if(!vis[v] && v != pa){

			dfs(v , u);

			child[u] += child[v];

		}

	}

}

int findcen(int u , int pa , int sz){

	for(int i = 0 ; i < adj[u].size() ; ++ i){

		int v = adj[u][i].fi;

		if(!vis[v] && child[v] > sz/2 && v != pa)

			return findcen(v , u , sz);

	}

	return u;

}

void dfs1(int u,int pa ,int pos){

	for(int i = 0 ; i < adj[u].size() ; ++i){

		int v = adj[u][i].fi , w = adj[u][i].se;

		if(!vis[v] && v != pa){

			d[v] = min(d[u] , w);

			vi[pos].pb(d[v]); all.pb(d[v]);

			dfs1(v,u,pos);

		}

	}

}

void dfs2(int u , int pa , int pos){

	int pos1 = upper_bound(all.begin(),all.end(),d[u]) - all.begin();

	int pos2 = upper_bound(vi[pos].begin(),vi[pos].end(),d[u]) - vi[pos].begin();

	ans[u] += d[u] * ( all.size() - pos1 + pos2 - vi[pos].size() + 1) + tcdall[pos1-1] - tcd[pos2-1];

	for(int i = 0 ; i < adj[u].size() ; ++i){

		int v = adj[u][i].fi ;

		if(!vis[v] && v != pa)

			dfs2(v,u,pos);

				

	}

}

void centroid(int root){

	dfs(root,root);

	if(child[root] == 1) return;

	int cen = findcen(root,root,child[root]);

	

	vis[cen] = true;

	memset(d,0x3f,sizeof d);

	all.clear();

	

	for(int i = 0 ; i < adj[cen].size() ; ++i){

		int v = adj[cen][i].fi , w = adj[cen][i].se;

		if(!vis[v]){

			vi[i].clear();

			d[v] = w; vi[i].pb(w); all.pb(w);

			dfs1(v,v,i);

		}

	}

	

	sort(all.begin() , all.end());

	for(int i = 0 ; i < all.size() ; ++ i){

		if( i == 0) tcdall[i] = all[i];

		else tcdall[i] = tcdall[i-1] + all[i];

	}

	for(int i = 0 ; i < adj[cen].size() ; ++i){

		int v = adj[cen][i].fi ;

		if(!vis[v]){

			sort(vi[i].begin() , vi[i].end());

			for(int j = 0 ; j < vi[i].size() ; ++ j){

				if( j == 0) tcd[j] = vi[i][j];

				else tcd[j] = tcd[j-1] + vi[i][j];

			}

			dfs2(v,v,i);		

		}

	}

	ans[cen] += tcdall[all.size()-1];

	for(int i = 0 ; i < adj[cen].size() ; ++i){

		int v = adj[cen][i].fi ;

		if(!vis[v]) centroid(v);

	}

}

signed main(){

	scanf("%d",&n);

	for(int i = 1 ; i < n ; ++ i ){

		int u , v , w;

		scanf("%d%d%d",&u,&v,&w);

		adj[u].pb(ii(v,w));

		adj[v].pb(ii(u,w));

	}

	centroid(1);

	for(int i = 1 ; i<= n ;++ i)

		printf("%lld\n",ans[i]);

}

// Faster C++ solution for the same problem (measured speedup: 1.3097029904438828x):
#include <bits/stdc++.h>



using namespace std;

#define int long long

int n;

vector<pair<int, pair<int, int> > > d;



int par[100005];

long long res[100005];

int lazy[100005];



vector<int> child[100005];



void Union(int u, int v, int w)

{

    if (child[par[u]].size() > child[par[v]].size())

    {

        swap(u, v);

    }

    int k = par[u];

    lazy[par[v]] += w*child[k].size();

    for (int i = 0; i < child[k].size(); i++)

    {

        par[child[k][i]] = par[v];

        res[child[k][i]] += w*child[par[v]].size() - lazy[par[v]] + lazy[k];

    }

    for (int i = 0; i < child[k].size(); i++)

    {

        child[par[v]].push_back(child[k][i]);

    }

    lazy[k] = 0;

    child[k].clear();

}



signed main()

{

    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n;

    for (int i = 1; i < n; i++)

    {

        int x, y, l; cin >> x >> y >> l;

        d.push_back({l,{x,y}});

    }

    for (int i = 1; i <= n; i++)

    {

        child[i].push_back(i);

        par[i] = i;

        lazy[i] = 0;

    }

    sort(d.begin(), d.end());

    memset(res, 0, sizeof res);

    memset(lazy, 0, sizeof lazy);

    reverse(d.begin(), d.end());

    for (int i = 0; i < n-1; i++)

    {

        Union(d[i].second.first, d[i].second.second, d[i].first);

    }

    for (int i = 1; i <= n; i++)

    {

        cout << res[i] + lazy[par[i]] << endl;

    }

}