_, Q = gets.split.map &:to_i
$parent = []

def trace_parent i
  stack = []
  t = i
  while $parent[t]
    stack << t
    t = $parent[t]
  end
  stack.each{|e|
    $parent[e] = t
  }
  t
end

Q.times{
  com, s, t = gets.split.map &:to_i
  if com == 0
    if $parent[s] == nil
      if $parent[t] == nil
        $parent[t] = s
      else
        root = trace_parent(t)
        $parent[s] = root unless s == root
      end
    elsif $parent[t] == nil
      root = trace_parent(s)
      $parent[t] = root unless t == root
    else
      root = trace_parent(s)
      $parent[t] = root
    end
  else
    puts trace_parent(s) == trace_parent(t) ? 1 : 0
  end
}