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