@Override
    public void connect(Integer p, Integer q) {
        int pId = numbers[p];
        int qId = numbers[q];

        if (pId == qId) {//they are already connected
            return;
        }

        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] == pId) {
                numbers[i] = qId;
            }
        }
    }