import java.util.*

fun main(args: Array<String>) {
    val result = solve(Scanner(System.`in`))
    if (result.isNotEmpty()) println(result)
}

fun solve(`in`: String) = solve(Scanner(`in`))


fun solve(sc: Scanner): String {
    val N = sc.nextInt()
    val AB = (1 until N).map { Pair(sc.nextInt(), sc.nextInt()) }
    val ans = Array(N - 1) { -1 }

    val T = Array(N) { mutableSetOf<Pair<Int, Int>>() }
    (0 until (N - 1)).forEach { wi ->
        val a = AB[wi].first - 1
        val b = AB[wi].second - 1
        T[a].add(Pair(b, wi))
        T[b].add(Pair(a, wi))
    }

    fun dfs(i: Int, color: Int = 0, prev: Int = -1) {
        var c = 0
        T[i].forEach { t ->
            val pi = t.first
            val wi = t.second
            if (pi != prev) {
                c++
                if (c == color) {
                    c++
                }
                ans[wi] = c
                dfs(pi, c, i)
            }
        }
    }
    dfs(0)

    return "${ans.max()}\n${ans.joinToString("\n")}"
}
