public void union(final int p, final int q) {
        final int pvalue = id[p];
        final int qvalue = id[q];
        for (int i = 0; i < n; i++) {
            if (i == pvalue) {
                id[i] = qvalue;
            }
        }
    }