data class Edge(val to: Int, val id: Int)
fun main(args: Array<String>) {
    val N = nextInt()
    val G = Array(N) { mutableListOf<Edge>() }
    val ans = IntArray(N - 1)
    repeat(N - 1) {
        val (a, b) = listOfInt(-1)
        G[a].add(Edge(b, it))
        G[b].add(Edge(a, it))
    }
    tailrec fun dfs(v: Int, c: Int = -1, p: Int = -1) {
        var k = 1
        for (e in G[v]) {
            val u = e.to
            val ei = e.id
            if (u == p) continue
            if (k == c) k++
            ans[ei] = k++
            dfs(u, ans[ei], v)
        }
    }
    dfs(0)
    val max = G.map { it.size }.max()!!
    println(max)
    println(ans.joinToString(separator = "\n"))
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun printErr(value: Any) = System.err.println(value)
