let solve (n, q) =
  let s = Array.init n (fun i -> i) in
  let rec find u =
    if u = s.(u) then u
    else begin
      s.(u) <- find s.(u);
      s.(u)
    end in
  for _ = 0 to q - 1 do
    let (n, x, y) = Scanf.scanf "%d %d %d " (fun n x y -> (n, x, y)) in
    if n = 0 then s.(find x) <- find y
    else print_endline (if find x = find y then "1" else "0")
  done

let () = Scanf.scanf "%d %d " (fun n q -> (n, q)) |> solve