class UnionFind
  def root(a)
    $parent[a] == a ? a : ($parent[a] = root($parent[a]))
  end

  def unite(a,b)
    x = root(a)
    y = root(b)
    if x != y then a < b ? $parent[y] = x : $parent[x] = y
    end
  end

  def same(a, b)
    a = root(a)
    b = root(b)
    if $parent[a] == $parent[b] then puts 1
    else puts 0
    end
  end
end

n, q = gets.split.map(&:to_i)
$parent = Array.new(n){ |i| i }
uf = UnionFind.new
q.times do
  cmd, x, y = gets.split.map(&:to_i)
  if cmd == 0 then uf.unite(x, y)
  else uf.same(x, y)
  end
end