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