// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

struct UnionFind {
    V<ll> rank;
    V<ll> parent;
    V<ll> size;
    V<ll> addv;
    VV<ll> edges;

    UnionFind(ll N) 
        : rank(N, 0), 
          parent(N), 
          size(N, 1),
          addv(N, 0),
          edges(N)
    {
        iota(parent.begin(), parent.end(), 0ll);
    }

    ll find(ll child) {
        return (child == parent[child] ? child : parent[child] = find(parent[child]));
    }

    void unit(ll x, ll y, ll c) {
        ll px = find(x);
        ll py = find(y);
        if(px == py) {
            return;
        }
        if(rank[px] < rank[py]) {
            swap(px, py);
        }
        parent[py] = px;
        addv[px] += size[py] * c;
        addv[py] += size[px] * c - addv[px];
        DEBUG(make_pair(px, size[px]), make_pair(py, size[py]), c);
        size[px] += size[py];
        edges[px].push_back(py);
        rank[px] += (rank[px] == rank[py]);
    }

    bool same(ll x, ll y) {
        return (find(x) == find(y));
    }

    void prog_value(ll now, ll pre, ll val) {
        addv[now] += val;
        for(ll nxt : edges[now]) {
            if(nxt == pre) continue;
            prog_value(nxt, now, addv[now]);
        }
    }

    void prog_value() {
        ll par;
        for(ll i = 0; i < parent.size(); i++) {
            if(this->find(i) == i) {
                par = i;
                break;
            }
        }
        prog_value(par, -1, 0);
    }
};

using TLL = tuple<ll, ll, ll>;

int main() {
    ll N;
    cin >> N;
    V<TLL> edges;
    for(ll i = 1; i < N; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        edges.emplace_back(c, a - 1, b - 1);
    }
    
    sort(ALLR(edges));

    UnionFind uf(N);
    for(const auto ele : edges) {
        ll c, a, b;
        tie(c, a, b) = ele;
        if(uf.same(a, b)) continue;
        uf.unit(a, b, c);
    }

    uf.prog_value();

    for(const auto val : uf.addv) cout << val << endl;
    return 0;
}


Measured memory_bytes: 11888