import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    // 双方向エッジ
    val edges = Array(N) { mutableListOf<Pair<Int, Int>>() }
    
    for (i in 0 until N - 1) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() - 1 }
        edges[a].add(Pair(i, b))
        edges[b].add(Pair(i, a))
    }
    
    var color = 0
    
    for (i in 0 until N) {
        color = Math.max(color, edges[i].size)
    }
    
    println(color)
    
    val nodeColor = IntArray(N)
    val ans = IntArray(N - 1)

    for (i in 0 until N - 1) {
        var nowColor = 1
        for (e in edges[i]) {
            if (ans[e.first] != 0) {
                continue
            }
            if (nowColor == nodeColor[i]) {
                ans[e.first] = nowColor + 1
                nodeColor[e.second] = nowColor + 1
                nowColor += 2
            } else {
                ans[e.first] = nowColor
                nodeColor[e.second] = nowColor
                nowColor++
            }
        }
    }

    for (c in ans) {
        println(c)
    }
}

fun readInputLine(): String {
    return readLine()!!
}
