n,q=gets.split.map(&:to_i)
l=[nil]*n
q.times do
  t,u,v=gets.split.map(&:to_i)
  if t==0
    s=[]
    while l[u]
      s << u
      u=l[u]
    end
    s << u
    while l[v]
      s << v
      v=l[v]
    end
    s << v
    u=[u,v].min
    s.each do |su|
      l[su]=u if su!=u
    end
  else
    s=[]
    while l[u]
      s << u
      u=l[u]
    end
    s.each do |su|
      l[su]=u
    end
    s=[]
    while l[v]
      s << v
      v=l[v]
    end
    s.each do |su|
      l[su]=v
    end
    if u==v
      puts 1
    else
      puts 0
    end
  end
end
