object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n  = sc.nextInt
	
	val connected = Array.fill(n)(scala.collection.mutable.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)
	val unpassed = Array.fill(n)(true)

	@scala.annotation.tailrec
	def bfs(q: Seq[(Int, Int)]): Unit = q match {
		case Seq() => ()
		case (v, pred) :: tail => {
			unpassed(v) = false
			connected(v).collect{ case (i, _) if cs(i) == -1 => i }.zipWithIndex.foreach{ case (i, ci) => 
				cs(i) = ci + (if (ci+1 >= pred) 2 else 1)
			}
			val cm = connected(v).map(cs apply _._1).max
			bfs(tail ++ connected(v).collect{ case (_, u) if unpassed(u) => (u, cm) })
		}
	}
	
	bfs(Seq((0, n)))
	
	println(cs.max)
	cs foreach (println(_))
}