N, Q = gets.split.map &:to_i
$nodes = *0...N
def root(a)
  while $nodes[a] != a do
    $nodes[a] = $nodes[$nodes[a]]
    a = $nodes[a]
  end
  a
  # a == $nodes[a] ? a : $nodes[a] = root($nodes[a])
end
def unite(a, b)
  $nodes[root(a)] = b
end
def same?(a, b)
  $nodes[root(a)] == $nodes[root(b)]
end

$<.map{|s|
  com, x, y = s.split.map &:to_i
  if com == 0
    unite(x, y)
  else
    p same?(x, y) ? 1 : 0
  end
}