n = gets.to_i
tree = []
total_count = Hash.new(0)
array = []
(n - 1).times do
  a, b  = gets.chomp.split(' ').map(&:to_i)
  array << [a, b]
  tree << [a, b]
  total_count[a] += 1
  total_count[b] += 1
end
tree.sort!
prev = tree[0]
counts = Hash.new(0)
val = 1
counts[prev] = val
(1...n - 1).each do |i|
  current = tree[i]
  if prev[0] == current[0] || prev[1] == current[0]
    val += 1
  else
    val = 1
  end
  counts[current] = val
  prev = current
end
puts total_count.map{ |_, v| v }.sort.last
array.each do |i|
  puts counts[i]
end