object Main extends App {
	import scala.collection.mutable.ArrayBuffer
	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)
	val unpassed = Array.fill(n)(true)

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