local mfl, mce = math.floor, math.ceil local n = io.read("*n") local edge = {} local size = {} local ccnt, parent = {}, {} for i = 1, n do edge[i] = {} size[i] = 1 ccnt[i] = 0 parent[i] = 0 end for i = 1, n - 1 do local a, b = io.read("*n", "*n") table.insert(edge[a], b) table.insert(edge[b], a) end local tasks = {1} for i = 1, n do local src = tasks[i] for j = 1, #edge[src] do local dst = edge[src][j] if parent[src] ~= dst then parent[dst] = src ccnt[src] = ccnt[src] + 1 table.insert(tasks, dst) end end end local ans = {} for i = 1, n do ans[i] = 0 end tasks = {} for i = 1, n do if ccnt[i] == 0 then table.insert(tasks, i) end end for i = 1, n do local src = tasks[i] local v = 0 local c = 0 local p = parent[src] local sz = size[src] for j = 1, #edge[src] do local dst = edge[src][j] if dst == p then size[p] = size[p] + sz ccnt[p] = ccnt[p] - 1 if ccnt[p] == 0 then table.insert(tasks, p) end else c = c + size[dst] v = v - mfl(size[dst] * (size[dst] - 1) / 2) end end v = v + mfl(c * (c - 1) / 2) ans[src] = v + sz - 1 end for i = 1, n do ans[i] = ans[i] * 2 + 1 end print(table.concat(ans, "\n"))