let main: () = {
    let N = nextInt()
    let C = listOfInt(-1)
    var G = Array(N) { _ in [Int]() }
    repeate(N - 1) { _ in
        let (a, b) = *listOfInt(-1)
        G[a].append(b)
        G[b].append(a)
    }
    var all = 0
    var cnt = Array<Int>(N), sub = Array<Int>(N)
    var ans = Array(N) { _ in N * (N - 1) / 2 }
    func dfs(_ v: Int, _ p: Int) -> Int {
        sub[v] = 1
        let bfr = cnt[C[v]]
        for u in G[v] {
            if (u == p) {continue}
            let pre = all - cnt[C[v]]
            sub[v] += dfs(u, v)
            let nxt = all - cnt[C[v]]
            ans[C[v]] -= (nxt - pre) * (nxt - pre - 1) / 2
        }
        cnt[C[v]] = bfr + sub[v]
        all += 1
        return sub[v]
    }
    _ = dfs(0, -1)
    repeate(N) { c in
        let pre = 0, nxt = N - cnt[c]
        ans[c] -= (nxt - pre) * (nxt - pre - 1) / 2
    }
    for c in C { ans[c] += 1}
    print(ans.joinToString("\n"))
}()

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
@inlinable func listOfInt(_ offset: Int = 0) -> [Int] { listOfString().map { Int($0)! + offset } }
extension Array {
    init(_ size: Int, _ initValue: ((Int) -> Element)) {
        self = [Element]()
        for index in 0 ..< size {
            let value = initValue(index)
            self.append(value)
        }
    }
}
extension Array where Element == Int {
    init(_ size: Int) {
        self = [Element]()
        for _ in 0 ..< size {
            self.append(0)
        }
    }
    @inlinable func joinToString(_ sepatator: String = " ") -> String { self.map { String($0) }.joined(separator: sepatator) }
}
prefix operator *
prefix func * <T> (a: [T]) -> (T, T) { (a[0], a[1]) }

@inlinable func repeate(_ times1: Int, _ action: (Int) -> Void) {
    for index1 in 0 ..< times1 {
        action(index1)
    }
}
