import java.util.*

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val nodes = Array(n) { mutableListOf<Pair<Int, Int>>() }
    val pColors = Array(n) { 0 }
    val ans = Array(n-1) { 0 }

    repeat(n-1) { idx ->
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        nodes[a-1].add(Pair(b-1, idx))
        nodes[b-1].add(Pair(a-1, idx))
    }

    val queue = ArrayDeque<Int>()
    val seen = Array(n){false}
    queue.add(0)

    while(queue.isNotEmpty()) {
        val idx = queue.poll()
        val node = nodes[idx]
        val pColor = pColors[idx]

        seen[idx] = true
        var newColor = 1

        node.forEach {
            if (seen[it.first]) return@forEach

            if (newColor == pColor) newColor++
            pColors[it.first] = newColor
            ans[it.second] = newColor
            queue.add(it.first)

            newColor++
        }
    }

    println(ans.toSet().size)
    println(ans.joinToString(separator = "\n"))
}