N = gets.to_i Q = [] N.times do |i| a, b = gets.split.map(&:to_i) Q << [i, [a, b]] end Q.sort_by! { |_i, (a, b)| [a, b].min } checked = Array.new(N + 1, false) ans = Array.new(N) Q.each do |i, (a, b)| if not checked[a] ans[i] = a checked[a] = true elsif not checked[b] ans[i] = b checked[b] = true else puts 'No' exit end end puts 'Yes' puts ans