fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val graph = Array(n) { mutableListOf<Int>() }
    val ea = IntArray(n-1)
    val eb = IntArray(n-1)

    repeat(n-1) {
	val (a, b) = readLine()!!.split(' ').map { it.toInt()-1 }
	ea[it] = a
	eb[it] = b
	graph[a].add(it)
	graph[b].add(it)
    }

    val ans = IntArray(n-1)
    val ord = IntArray(n)
    val parent = IntArray(n)
    val parentc = IntArray(n)
    var len = 1
    repeat(n) {
	val v = ord[it]
	var color = 1
	for (k in graph[v]) {
	    val w = ea[k] xor eb[k] xor v
	    if (w != parent[v]) {
		if (color == parentc[v]) color++
		parent[w] = v
		parentc[w] = color
		ans[k] = color
		ord[len++] = w
		color++
	    }
	}
    }

    println(ans.max())
    ans.forEach { println(it) }
}
