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)
  j, k = k, j if j > k


  if i == 0  # unite
    x, y = 0, 0
    data.each_with_index do |e, i|
      x = i if e.include?(j)
      y = i if e.include?(k)
    end
    next if x == y

    data[x] = data[x] + data[y]
    data.delete_at(y)

  else  #same
    result = 0
    data.each do |e|
      s = Set.new([j, k])
      flag = (s & e).size
      if flag == 1
        break
      elsif flag == 2
        result = 1
        break
      end
    end
    p result
  end
end