fun main(args: Array<String>) {
    abc146d()
}

private const val UNDEFINED = -1

private data class Edge(val to: Int, val index: Int)

fun abc146d() {
    val n = readLine()!!.toInt()
    val abList = (1 until n).map { readLine()!!.split(' ').map { it.toInt() - 1 } }
        .map { Pair(it[0], it[1]) }

    val graph = Array(n) { mutableListOf<Edge>() }
    abList.forEachIndexed { index, pair ->
        val (left, right) = pair
        graph[left].add(Edge(right, index))
        graph[right].add(Edge(left, index))
    }

    val lines = Array(n - 1) { UNDEFINED }

    fun dfs(index: Int, pIndex: Int, pColor: Int) {
        val edges = graph[index]
        var color = 0
        for (edge in edges) {
            if (edge.to == pIndex) continue
            if (lines[edge.index] != UNDEFINED) continue
            if (++color == pColor) color++
            lines[edge.index] = color
            dfs(edge.to, index, color)
        }
    }

    dfs(0, -1, -1)

    val answer = lines.joinToString(System.lineSeparator())
    println(graph.map { it.size }.max())
    println(answer)
}
