import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Edge = Tuple!(int, "to", int, "cost");

immutable long inf = 10L^^16;

void main() {
    int n;
    scan(n);

    bool c2 = 1;
    long ans;
    auto adj = new Edge[][](n + 1, 0);

    auto uf = UnionFind(n + 1);

    foreach (i ; 0 .. n - 1) {
        int ai, bi, ci;
        scan(ai, bi, ci);
        if (ci > 2) c2 = 0;
        adj[ai] ~= Edge(bi, ci);
        adj[bi] ~= Edge(ai, ci);

        if (ci == 2) {
            uf.unite(ai, bi);
        }
    }

    
    void dfs(int s, int v, int p, long mine) {
        if (s != v) {
            ans += mine;
        }

        foreach (e ; adj[v]) {
            if (e.to != p) {
                dfs(s, e.to, v, min(mine, e.cost));
            }
        }
    }

    if (c2) {
        foreach (i ; 1 .. n + 1) {
            int two = uf.countNodes(i);
            ans = 2 * (two - 1) + (n - two);
            writeln(ans);
        }
    }
    else if (n <= 2000) {
        foreach (i ; 1 .. n + 1) {
            ans = 0;

            dfs(i, i, 0, inf);

            writeln(ans);
        }
    }
}

struct UnionFind {
    private {
        int N;
        int[] p;
        int[] rank;
        int[] cnt;
    }

    this (int n) {
        N = n;
        p = iota(N).array;
        rank = new int[](N);
        cnt = repeat(1, N).array;
    }

    int find_root(int x) {
        if (p[x] != x) {
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        int u = find_root(x), v = find_root(y);

        if (u == v) return;

        if (rank[u] < rank[v]) {
            p[u] = v;
            cnt[v] += cnt[u];
            cnt[u] = 0;
        }
        else {
            p[v] = u;
            cnt[u] += cnt[v];
            cnt[v] = 0;

            if (rank[u] == rank[v]) {
                rank[u]++;
            }
        }
    }

    int countNodes(int x) {
        return cnt[find_root(x)];
    }
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}