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], pred: Int): Unit = q match {
		case Seq() => ()
		case v :: tail => {
			val uncolor = connected(v) filter { case (i, _) => cs(i) == -1 }
			unpassed(v) = false
			bfs(tail ++ uncolor.map(_._2).filter(unpassed(_)),
				(uncolor.zipWithIndex.map {case ((i, _), ci) => 
					cs(i) = ci + (if (ci >= pred) 2 else 1); cs(i)
				} :+ n+1).max - 1)
		}
	}
 
	bfs(Seq(0), n)
 
	println(cs.max)
	cs foreach (println(_))
}