class UnionFind
  def initialize(n)
    @par = Array.new(n){|x| x}
    @size = Array.new(n, 0)
  end

  def find(x)
    return x if x == @par[x]
    return @par[x] = find(@par[x])
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y
    swap(x, y) if @size[x] < @size[y]
    @par[y] = x
    @size[x] += @size[y]
  end

  def same(x, y)
    return find(x) == find(y)
  end

  def size(x)
    return @size[find(x)]
  end
end

n, q = gets.split.map(&:to_i)
uf = UnionFind.new(n)
q.times {
  com, x, y = gets.split.map(&:to_i)
  if com.zero?
    uf.unite(x, y)
  else
    p uf.same(x, y) ? 1 : 0
  end
}