import scala.collection.mutable.ArrayBuffer

object Main extends App {
	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, b = sc.nextInt - 1
		connected(a) += (i -> b)
		connected(b) += (i -> a)
	}
	
	val cs = Array.fill(n-1)(-1)
	println(connected.map(_.length).max)

	def bfs(q: Seq[(Int, Int)]): Unit = {
		val nexts = q flatMap { case (v, p) =>
			var ci = 1
			connected(v).collect{ case (i, u) if cs(i) == -1 =>
				cs(i) = ci + (if (ci < p) 0 else 1)
				ci += 1
				(u, cs(i))
			}
		}
		if (nexts.nonEmpty) bfs(nexts)
	}

	bfs(Seq((0, n)))

	cs foreach (println(_))
}