n = gets.to_i
a = []
b = []
(n-1).times do |i|
  a[i], b[i] = gets.chomp.split(" ").map(&:to_i)
end
max = 1
puts max

ans = Array.new(n+1).map{Array.new(n+1,0)}

(n-1).times do |i|
  puts ans[a[i]][b[i]]
end