#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 100005;
int n, fa[2 * N], size[2 * N], val[2 * N];
ll tag[2 * N];
struct edge
{
	int a, b, c;
} e[N];
vector<int> g[2 * N];
bool operator<(const edge &x, const edge &y) { return x.c > y.c; }

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

void dfs(int u)
{
	if (u <= n) size[u] = 1;
	for (int v : g[u]) dfs(v), size[u] += size[v];
	for (int v : g[u]) tag[v] += 1ll * (size[u] - size[v]) * val[u];
}
void get(int u)
{
	for (int v : g[u]) tag[v] += tag[u], get(v);
}

int main()
{
	scanf("%d", &n);
	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++) fa[i] = i;
	for (int i = 1; i < n; i++)
	{
		int s = find(e[i].a), t = find(e[i].b);
		fa[n + i] = n + i, val[n + i] = e[i].c;
		fa[s] = fa[t] = n + i;
		g[n + i].push_back(s), g[n + i].push_back(t);
	}
	dfs(2 * n - 1);
	get(2 * n - 1);
	for (int i = 1; i <= n; i++) printf("%lld\n", tag[i]);
}
