s=STDIN.gets.split
n = s[0].to_i
q = s[1].to_i
numbers = Array.new(n)
parent  = Array.new(n)
0.upto(n-1) {|i|
  numbers[i] = Array.new(1,i)
  parent[i]  = i
}
1.upto(q) {
s=STDIN.gets.split
com = s[0].to_i
x   = s[1].to_i
y   = s[2].to_i
#printf(":%d %d %d\n",com,x,y)
if com == 0 then
  if(x > y) then
    w = x
    x = y
    y = w
  end
  px = parent[x]
  py = parent[y]
  numbers[px] |= numbers[py]
  for i in numbers[py] do
    parent[i]=px
  end
elsif com == 1 then
  if(parent[x]==parent[y])
    puts 1
  elsif
    puts 0
  end
end
}