class UnionFind
  attr_accessor(:table)

  def initialize(n)
    @table = Array.new(n, -1)
  end

  def root(x)
    st = []
    tb = @table
    while tb[x] >= 0
      st.push(x)
      x = tb[x]
    end
    
    st.each do |y|
      @table[y] = x
    end
    
    return x
  end
  
  def find(x, y)
    return root(x) == root(y)
  end

  def union(x, y)
    r1 = root(x)
    r2 = root(y)
    return if r1 == r2
    
    d1 = @table[r1]
    d2 = @table[r2]
    if d1 <= d2
      @table[r2] = r1
      @table[r1] += d2
    else
      @table[r1] = r2
      @table[r2] += d1
    end
  end
end

n, q = gets.chomp.split.map(&:to_i)
uf = UnionFind.new(n)
q.times do
  t, u, v = gets.chomp.split.map(&:to_i)
  if t == 0
    uf.union(u, v)
  elsif t == 1
    puts (uf.find(u, v))? "1" : "0"
  end
end