type t = { mutable x : int; mutable y : int }

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let find_set s x =
  let rec doit x =
    if x <> s.(x).x then s.(x).x <- doit (s.(x).x);
    s.(x).x in
  doit x

let unite s x y =
  let (a, b) = (find_set s x, find_set s y) in
  if s.(a).y > s.(b).y then s.(b).x <- a
  else begin
    s.(a).x <- b;
    if s.(a).y = s.(b).y then s.(b).y <- s.(b).y + 1
  end

let same_p s x y = find_set s x = find_set s y

let solve n q =
  let s = Array.init n (fun i -> { x = i; y = 0}) in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> unite s x y
      | 1 :: x :: y :: _ -> print_endline (if same_p s x y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()