import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) g = [[] for _ in range(n)] for i in range(n-1): v, w = map(int, input().split()) v, w = v-1, w-1 g[v].append(w) g[w].append(v) s = [] order = [] parent = [-1]*n s.append(0) while s: v = s.pop() order.append(v) for u in g[v]: if parent[v] != u: s.append(u) parent[u] = v order.reverse() C = [1]*n for v in order: if parent[v] != -1: C[parent[v]] += C[v] #print(C) ans = [0]*n for v in order: for u in g[v]: if u == parent[v]: continue ans[v] += 2*C[u] ans[v] += (C[v]-1-C[u])*C[u] ans[v] += 1 print(*ans, sep='\n')