n = gets.to_i
graphs = []
(n - 1).times do
  graphs << gets.split.map(&:to_i)
end
rests = Array.new(n)
rests[0] = (1..n - 1).to_a
1.upto(n - 1).each do |index|
  rests[index] = rests[0].dup
end

answers = []
graphs.each do |a, b|
  a -= 1
  b -= 1
  saved_index = 0
  rests[b].each_with_index do |rest, index|
    a_index = rests[a][saved_index..-1].bsearch_index { |i| i >= rest }
    if rests[a][a_index] > rest
      saved_index = a_index
      next
    else
      rests[b].delete_at(index)
      rests[a].delete_at(a_index)
      answers << rest
      break
    end
  end
end
puts answers.uniq.size
answers.each do |a|
  puts a
end
