def find(x)
  while $ps[x][1] != x do
    x=$ps[x][1]
  end
  return x
end
def init(n)
  n.times{|i|
    $ps[i] = [0, i]
  }
end

def update(x,y)
  if $ps[x][0] > $ps[y][0]
    $ps[y][1] = x
  else
    $ps[x][1] = y
    if $ps[x][0] == $ps[y][0]
      $ps[y][0] += 1
    end
  end
end

$ps={}
n,q = gets.split.map(&:to_i)
init(n)
q.times{|i|
  com, x, y = gets.split.map(&:to_i)
  if com == 0
    x = find(x)
    y = find(y)
    update(x,y)
  else
    x = find(x)
    y = find(y)
    puts x==y ? 1 : 0
  end
}
