require 'pp'

n = gets.chomp!.to_i

tree = {}
tree_max = 0

index_memo = Array.new(n-1, nil)

(n-1).times do |i|
  a, b = gets.chomp!.split(" ").map(&:to_i)
  tree[a] ||= {}
  tree[b] ||= {}
  tree[a][b] = 0
  tree[b][a] = 0
  if tree[a].length > tree_max
    tree_max = tree[a].length
  end
  if tree[b].length > tree_max
    tree_max = tree[b].length
  end

  index_memo[i] = [a, b]
end

ng = Array.new(n-1, 0)
1.upto(n) do |num|
  count = 0
  tree[num].each do |k, _|
    if tree[num][k] == 0
      count += 1
      if ng[num] == count
        count += 1
      end
      ng[k] = count
      tree[num][k] = count
      tree[k][num] = count
    end
  end
end

#pp tree
#pp index_memo

puts tree_max
index_memo.each do |a, b|
  puts tree[a][b]
end
