cup = {0=>0, 1=>0, 2=>0} cup[gets.to_i - 1] = 1 (gets.to_i).times{ i, j = gets.split.map(&:to_i) cup[i-1],cup[j-1] = cup[j-1],cup[i-1] } cup.each{|key,value| if cup[key] == 1 puts key + 1 end }