#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
const ll INF = 1e9+7;
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};
ll N;
struct query {
    ll u;
    ll v;
    ll cost;
};

bool operator<(query &a, query &b) {
    return a.cost > b.cost;
}
/*
bool operator>(query &a, query &b) {
    return a.cost > b.cost;
}
*/
struct info {
    ll time;
    ll fun;
    ll next;
    bool operator<(info &b) {
        return time < b.time;
    }
};

bool comp (const info &a, const info &b) {
    return a.time < b.time;
};

/*
bool operator<(info &a, info &b) {
    return a.time < b.time;
}
*/
/*
bool operator>(info &a, info &b) {
    return a.time > b.time;
}
*/
vector<info> funny[100050];

ll answer(ll point, ll time) {
    info compare_before = {time, 0, 0};
    auto before = lower_bound(funny[point].begin(), funny[point].end(), compare_before, comp);
    //cout << before->time << " " << before->next << endl;
    auto after = funny[point].end() - 1;
    //cout << after->time << " " << after->next << endl;
    if(after->next == point) {
        return after->fun - before->fun;
    }
    return (after->fun - before->fun) + answer(after->next, after->time);
}

int main() {
    //cout.precision(10);
    UnionFind uni(100050);
    vector<query> queries;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        funny[i].push_back({-1, 0, i});
    }
    for(int i = 1; i < N; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        queries.push_back({a, b, c});
    }
    sort(queries.begin(), queries.end());
    for(int i = 0; i < queries.size(); i++) {
        query now = queries[i];
        ll u = uni.root(now.u);
        ll v = uni.root(now.v);
        ll size_u = uni.size(u);
        ll size_v = uni.size(v);
        ll now_fun_u = funny[u].back().fun;
        ll now_fun_v = funny[v].back().fun;
        uni.merge(u, v);
        ll NEW_parent = uni.root(u);
        funny[u].push_back({i, now_fun_u + size_v * now.cost, NEW_parent});
        funny[v].push_back({i, now_fun_v + size_u * now.cost, NEW_parent});
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << endl;
        for(int j = 0; j < funny[i].size(); j++) {
            //cout << funny[i][j].time << " " << funny[i][j].fun << " " << funny[i][j].next << endl;
        }
    }
    for(int i = 1; i <= N; i++) {
        cout << answer(i, -1) << endl;
    }
    return 0;
}


Measured memory_bytes: 18800