$UnionFindTree = Array.new(10001)
0.upto(10001) do |i|
  $UnionFindTree[i] = i
end

# todo: パス圧縮追加する
def root(x)
  if ($UnionFindTree[x] == x)
    x
  else
    $UnionFindTree[x] = root($UnionFindTree[x])
    $UnionFindTree[x]
  end
end

def unite(x, y)
  $UnionFindTree[root(x)] = root(y)
end

def same(x, y)
  puts (root(x) == root(y) ? "1" : "0")
end

if __FILE__ == $0
  n, q = gets.split.map(&:to_i)
  q.times do
    com, x, y = gets.split.map(&:to_i)
    com.zero? ? unite(x, y) : same(x, y)
  end
end