n, q = gets.chomp.split.map(&:to_i)
parent = (0...n).to_a
q.times{
    c, x, y = gets.chomp.split.map(&:to_i)

    px = x
    px = parent[px] while px != parent[px]
    py = y
    py = parent[py] while py != parent[py]

    case c
    when 0
        x, y = [px, py].minmax
        parent[y] = x
    when 1
        puts px == py ? "1" : "0"
    end
}

