n = read_line.to_i g = Array.new(n) { [] of Int32 } n.pred.times do v, w = read_line.split.map &.to_i.pred g[v] << w g[w] << v end def dfs(v : Int32, par : Int32, g : Array(Array(Int32)), ans : Array(Int64)) child, bottom = 1i64, 0i64 g[v].select { |i| par != i }.each { |u| r = dfs(u, v, g, ans) child += r bottom += r**2 } ans[v] = child**2 - bottom child end ans = [0i64]*n dfs(0, -1, g, ans) puts ans.join('\n')