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 int[] 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 a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; list.get(a).add(b); list.get(b).add(a); } br.close(); ans = new int[n]; ans[0] = dfs(0, -1); dfs2(0, -1); PrintWriter pw = new PrintWriter(System.out); for (int i : ans) { pw.println(i); } pw.flush(); } static int dfs(int x, int p) { int ret = 0; for (int i : list.get(x)) { if (i != p) { if (x > i) { ret++; } int res = dfs(i, x); ret += res; } } return ret; } static void dfs2(int x, int p) { for (int i : list.get(x)) { if (i != p) { if (x < i) { ans[i] = ans[x] + 1; } else { ans[i] = ans[x] - 1; } dfs2(i, x); } } } }