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

sets = {}
n.times {|i| sets[i] = [i]}

q.times do
	com, x, y = gets.split.map(&:to_i)

	case com
	when 0
		unless sets[x] == sets[y]
			sets[x] += sets[y]
			sets[y] = sets[x]
		end
	when 1
		p sets[x] == sets[y] ? 1 : 0
	end
end

