import java.util.*
fun main() {
    val n= readLine()!!.toInt()
    var tree= MutableList(n+1){ mutableListOf<Int>()}
    var memo= mutableMapOf<List<Int>, Int>()
    for (i in 1 until n){
        val (a,b)= readLine()!!.split(" ").map { it.toInt() }
        memo[listOf(a,b)]=i
        tree[a].add(b)
    }

    var que=ArrayDeque<List<Int>>()
    var visited=BooleanArray(n+1){i->i==0}
    que.addFirst(listOf(1,-1))
    visited[1]=true
    var ans=IntArray(n){0}
    while (que.isNotEmpty()){
        val now=que.removeFirst()
        var cnt=0
        for (i in tree[now[0]]){
            if (cnt==now[1]){cnt++}
            que.addFirst(listOf(i, cnt))
            visited[i]=true
            ans[memo[listOf(now[0], i)]!!]=cnt+1
            cnt++
        }
        ans[0]=Math.max(ans[0],cnt)
    }
    ans.forEach { println(it) }
}