code: public IntArrayList getConnectedComponentsT2() {
          boolean[] marked1 = new boolean[nodes1.size()];
          boolean[] marked2 = new boolean[nodes2.size()];
          
          IntArrayList roots = new IntArrayList();
          for (int t2=0; t2<nodes2.size(); t2++) {
              if (!marked2[t2]) {
                  roots.add(t2);
                  
                  // Depth first search.
                  dfs(t2, false, marked1, marked2, null);
              }
          }
          return roots;
      }
docs: Gets the connected components of the graph.
  @return A list containing an arbitrary node in each each connected component.