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) { long count = 1; ArrayList unders = new ArrayList<>(); for (int x : graph.get(idx)) { if (x == parent) { continue; } int y = getChildren(x, idx); unders.add(y); count += y; ans[idx] += y * 2; } for (int i = 0; i < unders.size() - 1; i++) { for (int j = i + 1; j < unders.size(); j++) { int x = unders.get(i); ans[idx] += (long)x * unders.get(j) * 2; } } ans[idx]++; return (int)count; } }