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}

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'
    # id[x] ???????´???§ id[y] ???????´??????¨??????????????????
    for j in 0..n
      id[j] = id[x] if id[j] == id[y]
    end
  else
    puts id[x] == id[y] ? "1" : "0"
  end
end