import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; public class Main { static int n; static List> list; static Obj[] ans; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); n = Integer.parseInt(sa[0]); list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { sa = br.readLine().split(" "); int v = Integer.parseInt(sa[0]) - 1; int w = Integer.parseInt(sa[1]) - 1; list.get(v).add(w); list.get(w).add(v); } br.close(); ans = new Obj[n]; dfs(0, -1); PrintWriter pw = new PrintWriter(System.out); for (Obj o : ans) { pw.println(o.val); } pw.flush(); } static Obj dfs(int x, int p) { Obj o = new Obj(); long total = 0; for (int c : list.get(x)) { if (c != p) { Obj res = dfs(c, x); o.size += res.size; total += res.total; } } o.size++; o.total = (long) o.size * o.size; o.val = o.total - total; return ans[x] = o; } static class Obj { int size; long val, total; } }