#!/usr/bin/env ruby

def read()
  gets(chomp: true)
end

def max_count(edges)
  edges.flatten.group_by {|n| n }.map { |_,n| n.count}.max
end

def calc_color(colors)
  max = colors.max()
  count = colors.count()
  if (count == 0)
    1
  elsif (count == max)
    max + 1
  else
    count
  end
end

def put_edge_color(edges)
  colors = Array.new(N) { [] }
  edges.reduce(colors) {|acc, edge|
    target, child = edge
    target_colors = acc[target-1]
    color = calc_color(target_colors)
    puts color
    acc[target-1] << color
    acc[child-1] << color
    acc
  }
end

N = read.to_i
edges = (1...N).map do
  read.split().map(&:to_i)
end

puts max_count(edges)
put_edge_color(edges)