if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  require 'rubygems'
  RUBY=Gem.ruby
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'10000000000'},RUBY,$0)
end

class UnionFind
  def initialize ( n )
    @parents = n.times.to_a
  end

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

  def unite ( x, y )
    @parents[find(x)] = @parents[y]
  end

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

n,q = gets.split.map(&:to_i)

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