#!/usr/bin/ruby

class Node

  attr_reader :num, :raw, :painted
  def initialize(num)
    @num = num
    @raw = {}
    @painted = []
  end

  @@list = Hash.new { |h,k| h[k] = self.new(k) }
  def self.list
    @@list
  end
  def self.get(num)
    @@list[num]
  end
end

class Line
  attr_reader :index, :node
  attr_accessor :color
  def initialize(i, a, b)
    @index = i
    @node = { a => Node.get(a), b => Node.get(b) }
    @node[a].raw[i] = self
    @node[b].raw[i] = self
    @color = nil
  end
end

n = ARGF.gets.to_i
lines = (n-1).times.map do |i|
  a, b = ARGF.gets.split.map(&:to_i)
  Line.new(i, a, b)
end

puts Node.list.map {|k,n| n.raw.length }.max

while node = Node.list.first
  queue = [node[1]]
  while node = queue.shift

    Node.list.delete(node.num)

    palette = (0...(node.raw.length + node.painted.length)).to_a
    node.painted.each { |line| palette[line.color] = nil }
    palette.compact!

    while lineindex = node.raw.shift
      index, line = lineindex

      line.color = palette.shift
      node.painted.push(node.raw.delete(index))
      line.node.delete(node.num)
      num, peer = line.node.shift
      peer.painted.push(peer.raw.delete(index))
      queue.push(peer) if peer.raw.length > 0
    end
  end
end

lines.each { |line| puts line.color + 1 }
