object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n  = sc.nextInt
	val ab = Array.tabulate(n-1)((_, sc.nextInt - 1, sc.nextInt - 1))
 
	val connected = Seq.tabulate(n)(v => ab collect {
		case (i, a, b) if a == v => (i, b)
		case (i, a, b) if b == v => (i, a)
	})
 
	val cs = Array.fill(n-1)(-1)
 
	@scala.annotation.tailrec
	def bfs(seq: Seq[Int]): Unit = seq match {
		case Seq() => ()
		case v :: tail => {
			val (uncolor, colored) = connected(v) partition { case (i, _) => cs(i) == -1 }
			val cm = if (colored.nonEmpty) colored.map(cs apply _._1).max else n+1
			uncolor.zipWithIndex.foreach { case ((i, _), ci) =>
				cs(i) = ci + (if (ci+1 >= cm) 2 else 1)
			}
			bfs(tail ++ uncolor.map(_._2))
		}
	}
 
	bfs(Seq(0))
 
	println(cs.max)
	cs foreach (println(_))
}