fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val graph = Array(n) {
        mutableListOf<Int>()
    }
    val colorMap = mutableMapOf<Points, Int>()
    val used = mutableMapOf<Points, Boolean>()

    val input = Array(n - 1) {
        readLine()!!.split(" ").map { it.toInt() - 1 }
    }
    input.forEach { list ->
        val (a, b) = list
        graph[a].add(b)
        used[Points(a, b)] = false
        graph[b].add(a)
        used[Points(b, a)] = false
    }
    fun bfs(from: Int, v: Int, color: Int) {
        //println("from:$from to:$v")
        if (from != -1) {
            used[Points(from, v)] = true
            used[Points(v, from)] = true
            colorMap[Points(from, v)] = color
            colorMap[Points(v, from)] = color
        }

        var toColor = 1
        graph[v].forEach { u ->
            if (used[Points(v, u)]!!) return@forEach
            if (color == toColor) {
                toColor++
                bfs(v, u, toColor)
                toColor++
            } else {
                bfs(v, u, toColor)
                toColor++
            }
        }
    }
    bfs(-1, 0, 0)
    println(graph.map { it.size }.max()!!)
    input.forEach { list ->
        val (a, b) = list
        println(colorMap[Points(a, b)])
    }
}

data class Points(val u: Int, val v: Int)