import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val tree = Array.fill[List[(Int, Int)]](N+1)(Nil) // (to, ind)
  for (i <- 1 to N-1) {
    val a, b = in.next().toInt
    tree(a) = (b, i) :: tree(a)
    tree(b) = (a, i) :: tree(b)
  }

  //
  val color = tree.map(_.length).max
  val ans = new Array[Int](N)

  case class Node(n: Int, preColor: Int)
  val stack = new Stack[Node]()

  var _color = 1
  for ((e, i) <- tree(1)) {
    ans(i) = _color
    val node = Node(e, _color)
    _color += 1
    stack.push(node)
  }

  while (!stack.isEmpty) {
    val Node(n, preColor) = stack.pop()

    var color = 1

    for ((e, ind) <- tree(n) if ans(ind) == 0) {
      if (color == preColor)
        color += 1

      val node = Node(e, color)
      stack.push(node)

      ans(ind) = color
      color += 1
    }

  }

  pw.println(color)
  ans.drop(1).foreach(pw.println)

  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
