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

hash = Hash.new{|h,k| h[k] = []}
arr = []
n.times{|i|
  arr[i] = i
  hash[i] << i
}

q.times{
  com, x, y = gets.split.map(&:to_i)
  case com
  when 0
    break if arr[x] == arr[y]
    old = arr[y]
    hash[old].each{|i|
      arr[i] = arr[x]
      hash[x] << i
    }
    hash.delete(old)
  when 1
    if arr[x] == arr[y] then
      puts "1"
    else
      puts "0"
    end
  end
}