using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var map = NMap(n - 1); var tree = new List[n]; for (var i = 0; i < n; ++i) tree[i] = new List(); foreach (var edge in map) { tree[edge[0]].Add(new Pair(edge[1])); tree[edge[1]].Add(new Pair(edge[0])); } var ans = new int[n]; DFS1(-1, 0, tree, ans); DFS2(-1, 0, 0, tree, ans); WriteLine(string.Join("\n", ans)); } class Pair { public int To; public int Val; public Pair(int to) { To = to; } } static void DFS1(int prev, int cur, List[] tree, int[] ans) { foreach (var next in tree[cur]) { if (prev == next.To) continue; DFS1(cur, next.To, tree, ans); next.Val = ans[next.To] + (cur > next.To ? 1 : 0); ans[cur] += next.Val; } } static void DFS2(int prev, int cur, int take, List[] tree, int[] ans) { ans[cur] += take; if (prev >= 0 && prev < cur) ++ans[cur]; foreach (var next in tree[cur]) { if (prev == next.To) continue; DFS2(cur, next.To, ans[cur] - next.Val, tree, ans); } } }