import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List edges = new ArrayList<>(); for(int i = 0 ; i < n - 1 ; i++){ int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; Edge edge = new Edge(a , b); edges.add(edge); } Graph graph = new Graph(edges , n); int[] ansArr = new int[n]; boolean[] seen = new boolean[n]; int ans = 0; ansArr[0] = dfs(graph , 0 , seen , ans); for(int i = 0 ; i < n ; i++){ seen = new boolean[n]; seen[i] = true; ansArr = dfs(graph , i , seen , ansArr); } for(int i = 0 ; i < n ; i++){ System.out.println(ansArr[i]); } } private static int dfs(Graph graph , int v , boolean[] seen , int ans){ seen[v] = true; for(Edge edge : graph.getEdgsList(v)){ int next_v = edge.getTo(); if(seen[next_v]){ continue; } if(next_v < v){ ans++; } ans = dfs(graph , next_v , seen , ans); } return ans; } private static int[] dfs(Graph graph , int v , boolean[] seen , int[] ansArr){ seen[v] = true; for(Edge edge : graph.getEdgsList(v)){ int next_v = edge.getTo(); if(seen[next_v]){ continue; } if(next_v > v){ ansArr[next_v] = ansArr[v] + 1; }else{ ansArr[next_v] = ansArr[v] - 1; } ansArr = dfs(graph , next_v , seen , ansArr); } return ansArr; } } //グラフのエッジ(辺)を格納するクラス class Edge { private int from, to; /**コンストラクタ * @param : from 頂点 * @param : to つながっている頂点 */ Edge(int from, int to) { this.from = from; this.to = to; } public int getFrom(){ return from; } public int getTo(){ return to; } public void setFrom(int from){ this.from = from; } public void setTo(int to){ this.to = to; } } //無向グラフクラス class Graph { //隣接リストを表すリストのリスト(ある頂点が、どの頂点とつながっているかを保持するリスト) Map> edgeMap = new HashMap<>(); /**コンストラクタ * @param edges : 辺 * @param n : 頂点の個数 * */ Graph(List edges, int n) { for (int i = 0; i < n; i++) { edgeMap.put(i ,new ArrayList<>()); } //無向グラフにエッジを追加します for (Edge edge: edges) { int from = edge.getFrom(); int to = edge.getTo(); List tmp1 = edgeMap.get(from); tmp1.add(edge); edgeMap.put(from , tmp1); List tmp2 = edgeMap.get(to); Edge tmpEdge = new Edge(to , from); tmp2.add(tmpEdge); edgeMap.put(to , tmp2); } } public int size() { return edgeMap.size(); } public List getEdgsList(int vNum) { return edgeMap.get(vNum); } }