require 'pp'

module MyTree
  class Tree
    attr_accessor :nodes, :edges, :num_nodes, :num_edges, :max_edge_node, :edge_colors

    def initialize
      @nodes = []
      @edges = []
      @num_nodes = 0
      @num_edges = 0
      @max_edge_node = nil
    end

    def find_or_initialize_node(number:)
      n = nodes.find { |node| node.number == number }
      if n
        n
      else
        node = Node.new(number: number)
        nodes << node
        self.num_nodes += 1
        node
      end
    end

    def add_edge(node_1_number:, node_2_number:)
      node_1 = find_or_initialize_node(number: node_1_number)
      node_2 = find_or_initialize_node(number: node_2_number)
      e = Edge.new(node_1: node_1, node_2: node_2)
      edges << e
      self.num_edges += 1
      [node_1, node_2].each do |n|
        n.add_edge(edge: e)
        @max_edge_node = n if max_edge_node.nil? || max_edge_node.edge_count < n.edge_count
      end
    end
  end

  class Node
    attr_accessor :number, :edges, :edge_count, :edge_colors

    def initialize(number:)
      @number = number
      @edges = []
      @edge_count = 0
      @edge_colors = []
    end

    def add_edge(edge:)
      edges << edge
      self.edge_count += 1
    end
  end

  class Edge
    attr_accessor :nodes, :color

    def initialize(node_1:, node_2:)
      @nodes = [node_1, node_2]
      @color = nil
    end

    def set_color(color_list:)
      return if self.color
      available_color = color_list - nodes.first.edge_colors - nodes.last.edge_colors
      raise 'No Color Available.' if available_color.empty?
      self.color = available_color.first
      nodes.each { |n| n.edge_colors << color }
    end

    def other_side_node(node:)
      n = nodes.reject { |n| n == node }
      return nil if n.length > 1
      n.last
    end
  end
end

t = MyTree::Tree.new
n = gets.to_i
(n-1).times do
  a, b = gets.chop.split.map(&:to_i)
  t.add_edge(node_1_number: a, node_2_number: b)
end
num_color = t.max_edge_node.edge_count
color_list = (1..num_color).to_a

tmp_nodes = [t.max_edge_node]
loop do
  break if tmp_nodes.empty?
  tmp_nodes_2 = []
  tmp_nodes.each do |tmp_node|
    tmp_node.edges.each { |e| tmp_nodes_2 << e.other_side_node(node: tmp_node) if e.set_color(color_list: color_list) }
  end
  tmp_nodes = tmp_nodes_2.uniq
end
puts num_color
t.edges.each { |e| puts e.color }