class DisjointSet

  def initialize n
    @ps = n.times.map.to_a
  end

  def union x, y
    x = find x
    y = find y
    @ps[y] = x
  end

  def find x
    if x == @ps[x]
      x
    else
      @ps[x] = find @ps[x]
    end
  end

end

n, q = gets.split.map &:to_i
ds = DisjointSet.new n
q.times do
  c, x, y = gets.split.map &:to_i
  if c.zero?
    ds.union x, y
  else
    p ds.find(x) == ds.find(y) ? 1 : 0
  end
end