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

@root = Array.new(n + 1) {|i| i}
def find(x); @root[x] = @root[x] == x ? x : find(@root[x]); end
def union(x,y); (x = find(x)) == (y = find(y)) or @root[x] = y ; end

q.times do
    t, u, v = gets.split.map &:to_i
    if t == 0
        union u, v
    else
        a = find u
        b = find v

        puts a == b ? 1 : 0
    end
end