# frozen_string_literal: true

N = gets.to_i
graph = Array.new(N) { [] }
list = []

(N - 1).times do
  a, b = gets.split.map!(&:to_i).map!(&:pred)
  graph[a] << b
  graph[b] << a
  list << [a, b]
end

queue = [0]
prev = [0]
edge = {}
k = 1

while queue.any?
  v = queue.shift
  color = 1

  graph[v].each do |i|
    next if prev[i]

    color += 1 if color == prev[v]
    k = color if k < color
    queue << i
    edge[[v, i]] = edge[[i, v]] = prev[i] = color
    color += 1
  end
end

puts k
list.each { |i| puts edge[i] }