public void union(int p, int q) {
    List<Integer> newCompent = new ArrayList<Integer>();
    newCompent.add(p);
    newCompent.add(q);
    List<Integer> mergeIndexs = new ArrayList<Integer>();
    for(List<Integer> compent: compentList) {
      if (compent.contains(p) || compent.contains(q)) {
        newCompent.addAll(compent);
        mergeIndexs.add(compentList.indexOf(compent));
      }
    }

    // merge to newCompent already.
    for(Integer i: mergeIndexs) {
      compentList.remove(i);
    }

    compentList.add(newCompent);
  }