# coding: utf-8

lines = $stdin.read

array = lines.split("\n")

n = array[0].split(" ")[0].to_i
q = array[0].split(" ")[1].to_i

it = -1
id = Array.new(n){it+=1}
it = -1
sn = Array.new(n){it+=1}

for i in 1..q
  com = array[i].split(" ")[0]
  x   = array[i].split(" ")[1].to_i
  y   = array[i].split(" ")[2].to_i

  if com == '0'
    #puts "unite #{x}, #{y}"
    if id[x] == y or id[y] == x
      #puts "ignore, already united"
    else
      if id[x] != x
        id[y] = x
      else
        id[x] = y
      end
    end

    #puts sn.to_s
    #puts id.to_s
    #puts ""
  else
    #puts "same #{x}, #{y} ?"
    # ???????????????root????±???????
    x_root = x
    y_root = y

    x_elem = []
    y_elem = []

    x_no_root = false
    y_no_root = false

    loop {
      if id[x] == x
        #printf "id[x](=%d) == x(=%d)\n", id[x], x
        x_root = x
        break
      elsif x_elem.include? id[x]
        # no root!
        #printf "no root! %s\n", x_elem.to_s
        x_no_root = true
        break
      else
        #printf "id[x](=%d) != x(=%d)\n", id[x], x
        x_elem.push(id[x])
        x = id[x]
      end
    }

    loop {
      if id[y] == y
        #printf "id[y](=%d) == y(=%d)\n", id[y], y
        y_root = y
        break
      elsif y_elem.include? id[y]
        # no root!
        #printf "no root! %s\n", y_elem.to_s
        y_no_root = true
        break
      else
        #printf "id[y](=%d) != y(=%d)\n", id[y], y
        y_elem.push(id[y])
        y = id[y]
      end
    }

    if x_no_root and y_no_root
      #puts "*"
      puts x_elem.sort == y_elem.sort ? "1" : "0"

    elsif x_no_root and not y_no_root
      #puts "**"
      puts x_elem.include?(y_root) ? "1" : "0"

    elsif not x_no_root and y_no_root
      #puts "***"
      puts y_elem.include?(x_root) ? "1" : "0"

    else
      #puts "****"
      puts x_root == y_root ? "1" : "0"

    end
  end
end