lines=readlines(chomp: true).map{|line| line.split(' ').map(&:to_i)}
n_q=lines.shift
datas =[]
lines.each do |query|
    if query[0]==0 then#unite selected sets
        elem1=[]
        elem2=[]
        datas.each do |data|
            if !elem1.empty? && !elem2.empty? then
                break
            elsif data.include?(query[1]) then
                elem1 = data
            elsif data.include?(query[2]) then
                elem2 = data
            end
        end
        if elem1.empty? then
            elem1=[query[1]]
        else
            datas.delete(elem1)
        end
        if elem2.empty? then
            elem2=[query[2]]
        else
            datas.delete(elem2)
        end
        datas << elem1.concat(elem2)
    else #query[0]==1, determine whether two selected elements are in the same sets
        is_exist = 0
        datas.each do |data|
            if data.include?(query[1]) || data.include?(query[2]) then
                if data.include?(query[1]) && data.include?(query[2]) then
                    is_exist = 1
                    break
                end
            end
        end
        puts is_exist
    end
end
