public void union(int x, int y) {
        int x_id = id[x];
        int y_id = id[y];
        int n = id.length;
        for (int i = 0; i < n; i++) {
            if (id[i] == x_id) {
                id[i] = y_id;
            }
        }
    }