import java.util.*; import java.io.*; public class Main { public static Scanner sc = new Scanner(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int T = 1; while( T > 0 ) { solve(); T--; } pw.flush(); } static void solve() { int N = sc.nextInt(); int[] dx = new int[N]; int[] dy = new int[N]; boolean[] vx = new boolean[N]; boolean[] vy = new boolean[N]; int offset = 0; LinkedList deque = new LinkedList<>(); ArrayList> edge = new ArrayList<>(); for( int i = 0; i < N; i++ ) { edge.add(new ArrayList<>()); dx[i] = dy[i] = Integer.MAX_VALUE; } for( int i = 0; i < N-1; i++ ) { int a = sc.nextInt()-1; int b = sc.nextInt()-1; edge.get(a).add(b); edge.get(b).add(a); } dx[0] = dy[0] = 0; deque.offer(0); while( !deque.isEmpty() ) { int now = deque.poll(); if( vx[now] ) continue; vx[now] = true; for( int next : edge.get(now) ) { if( !vx[next] && dx[now]+1 < dx[next] ) { dx[next] = dx[now]+1; deque.offer(next); } } } deque.offer(0); while( !deque.isEmpty() ) { int now = deque.poll(); if( vy[now] ) continue; vy[now] = true; for( int next : edge.get(now) ) { int k = now > next ? 1 : 0; if( !vy[next] && dy[now]+k < dy[next] ) { offset += k; dy[next] = dy[now]+k; deque.offer(next); } } } // pw.println(offset); for( int i = 0; i < N; i++ ) { // pw.println(dx[i]+" "+dy[i]); pw.println(offset+dx[i]-2*dy[i]); } } }