class UnionFind
  def initialize(n)
    @parents = Array.new(n, -1) # if negative value means size
  end

  def unite(a, b)
    a = root(a)
    b = root(b)

    return false if a == b

    a, b = b, a if -@parents[a] < -@parents[b]
    @parents[a] += @parents[b] # if negative value means size
    @parents[b] = a
    true
  end

  def root(a)
    @parents[a] < 0 ? a : (@parents[a] = root(@parents[a]))
  end

  def same?(a, b)
    root(a) == root(b)
  end

  def size(a)
    -@parents[root(a)]
  end
end

n, q = gets.split.map { |e| e.to_i }

uf = UnionFind.new(n)

q.times do
  t, u, v = gets.split.map { |e| e.to_i }
  
  if t == 0
    uf.unite(u, v)
  else
    puts (uf.same?(u, v) ? 1 : 0)
  end
end
