import java.util.LinkedList

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val edges = List(n) { mutableListOf<Pair<Int, Int>>() }
    for (i in 0 until n - 1) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        edges[a - 1].add(Pair(b - 1, i))
        edges[b - 1].add(Pair(a - 1, i))
    }
    var ret = 0
    val colors = Array(n - 1) { -1 }
    val queue = LinkedList(listOf(Triple(0, -1, -1)))
    while (queue.size > 0) {
        val (current, parent, pcolor) = queue.pop()
        var color = 1
        for ((next, index) in edges[current]) {
            if (color == pcolor) {
                color = color + 1
            }
            if (next != parent) {
                colors[index] = color
                queue.push(Triple(next, current, color))
                color = color + 1
            }
        }
        ret = Math.max(ret, color - 1)
    }

    println(ret)
    for (i in 0 until n - 1) {
        println(colors[i])
    }
}
    
