import scala.collection.mutable.ArrayBuffer

object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n  = sc.nextInt
	
	val connected = Array.fill(n)(ArrayBuffer.empty[(Int, Int)])
	(0 until n-1) foreach { i =>
		val a = sc.nextInt - 1
		val b = sc.nextInt - 1
		connected(a) += (i -> b)
		connected(b) += (i -> a)
	}
	
	val cs = Array.fill(n-1)(-1)

	def bfs(q: Seq[(Int, Int)]): Unit =
		if (q.isEmpty) ()
		else bfs(q flatMap { case (v, p) =>
			connected(v).filter{ case (i, _) => cs(i) == -1 }.zipWithIndex.map{ case ((i, u), ci) =>
				cs(i) = ci + 1 + (if (ci+1 < p) 0 else 1)
				(u, cs(i))
			}
		})

	bfs(Seq((0, n)))

	println(cs.max)
	cs foreach (println(_))
}