class DisjointSet
    def initialize(n)
        @parent = Array.new(n){-1}
    end
    def find(a)
        return a if @parent[a]<0
        @parent[a] = find(@parent[a])
    end
    def union(a, b)
        x = find(a)
        y = find(b)
        return x if x == y
        if size(x) < size(y)
            t = x
            x = y
            y = t
        end
        @parent[x] += @parent[y]
        @parent[y] = x
        x
    end
    def size(a)
        -@parent[find(a)]
    end
end 

N,Q=gets.split.map(&:to_i)
ds=DisjointSet.new(N)
Q.times{
	t,u,v=gets.split.map(&:to_i)
	case t
	when 0
		ds.union(u,v)
	when 1
		puts ds.find(u)==ds.find(v) ? 1 : 0
	end
}
