public ArrayList<ArrayList<Node>> ConnectedComponents(HierarchicalUndirectedGraph hgraph) {
        componentCount = 0;   
        int componentsSize[];        
        List<Integer> sizeList = new ArrayList<Integer>();
        ArrayList<ArrayList<Node>> componentListofList = new ArrayList<ArrayList<Node>>();                
        int N = hgraph.getNodeCount();

        //Keep track of which nodes have been seen
        int[] color = new int[N];        
        
        int seenCount = 0;
        while (seenCount < N) {
            ArrayList<Node> componentList = new ArrayList<Node>();
            //The search Q
            LinkedList<Node> Q = new LinkedList<Node>();
            //The component-list
            LinkedList<Node> component = new LinkedList<Node>();

            //Seed the search Q
            NodeIterable iter = hgraph.getNodes();
            for (Node first : iter) {
                if (color[indices.get(first)] == 0) {
                    Q.add(first);
                    iter.doBreak();
                    break;
                }
            }

            //While there are more nodes to search
            while (!Q.isEmpty()) {                
                //Get the next Node and add it to the component list
                Node u = Q.removeFirst();
                component.add(u);

                //Iterate over all of u's neighbors
                EdgeIterable edgeIter = hgraph.getEdgesAndMetaEdges(u);

                //For each neighbor
                for (Edge edge : edgeIter) {
                    Node reachable = hgraph.getOpposite(u, edge);
                    int id = indices.get(reachable);
                    //If this neighbor is unvisited
                    if (color[id] == 0) {
                        color[id] = 1;
                        //Add it to the search Q
                        Q.addLast(reachable);
                        //Mark it as used 
                    }
                }
                color[indices.get(u)] = 2;
                seenCount++;
            }
            
            for (Node s : component) {
                componentList.add(s);
            }
            componentListofList.add(componentList);
            componentCount++;            
        }                        
        return componentListofList;
    }