# 集合の要素の管理は不要
# ある値がどこに属しているかが把握できれば良い
class Set
	attr_writer :overwrite

	def head
		return self unless @overwrite

		t = @overwrite.head
		@overwrite = t if t
		return @overwrite
	end
end

n, q = gets.split.map(&:to_i)

affiliation = []
n.times {|i| affiliation[i] = Set.new}

q.times do
	com, x, y = gets.split.map(&:to_i)
	set_x = affiliation[x].head
	set_y = affiliation[y].head

	case com
	when 0
		unless set_x == set_y
			set_x.overwrite = set_y.overwrite = Set.new
		end
	when 1
		p set_x == set_y ? 1 : 0
	end
end

