require 'set'

n,q = gets.split.map(&:to_i)
data = []

0.upto(n-1) do |i|
  data << Set.new([i])
end
q.times do
  i,j,k = gets.split.map(&:to_i)
  # unite
  if i == 0
    x,y = 0,0
    data.each_with_index do |e,i|
      x = i if e.include?(j)
      y = i if e.include?(k)
    end
    data[x] = data[x] + data[y]
    data.delete_at(y)
  else #same
    r = 0
    data.each do |e|
      r = 1 if e.include?(j) && e.include?(k)
    end
    p r
  end
end