import java.util.*; import java.io.*; public class Main { static ArrayList> graph = new ArrayList<>(); static long[] ans; public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]) - 1; int b = Integer.parseInt(line[1]) - 1; graph.get(a).add(b); graph.get(b).add(a); } ans = new long[n]; getChildren(0, 0); StringBuilder sb = new StringBuilder(); for (long x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } static int getChildren(int idx, int parent) { int count = 1; for (int x : graph.get(idx)) { if (x == parent) { continue; } int y = getChildren(x, idx); ans[idx] += 2L * y * count; count += y; } ans[idx]++; return count; } }