class DisjointSet
  attr_accessor :n

  class Node
    attr_accessor :p, :rank

    def initialize
      @p, @rank = 0, 0
    end
  end

  def initialize(size)
    @n = Array.new(size) { Node.new }
    (0..size-1).each { |i| @n[i].p = i }
  end

  def unite(x, y)
    link(find_set(x), find_set(y))
  end

  def link(x, y)
    if @n[x].rank > @n[y].rank
      @n[y].p = x
    else
      @n[x].p = y
      @n[y].rank += 1 if @n[x].rank == @n[y].rank
    end
  end

  def find_set(x)
    if x != @n[x].p
      @n[x].p = find_set(@n[x].p)
    end
    return @n[x].p
  end

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

#main
n, q = gets.split.map &:to_i
ds = DisjointSet.new(n)
q.times do
  com, x, y = gets.split.map &:to_i
  case com
  when 0
    ds.unite(x, y)
  when 1
    puts ds.same(x, y) ? 1 : 0
  end
end