s=STDIN.gets.split
n = s[0].to_i
q = s[1].to_i
parent  = Array.new(n)
0.upto(n-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
  px = parent[x]
  py = parent[y]
  if(px != py) then
    if(px > py) then
      w = px
      px = py
      py = w
    end
    0.upto(n-1) {|i|
      parent[i] = px if parent[i]==py
    }
  end
elsif com == 1 then
  if(parent[x]==parent[y])
    puts 1
  elsif
    puts 0
  end
end
}