public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
        if (node == null) {
            return null;
        }
        
        HashMap<UndirectedGraphNode,UndirectedGraphNode> map = 
                     new HashMap<UndirectedGraphNode, UndirectedGraphNode>();
        Queue<UndirectedGraphNode> queue = new LinkedList<UndirectedGraphNode>();
        queue.offer(node);
        UndirectedGraphNode newroot = new UndirectedGraphNode(node.label);
        map.put(node, newroot);
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                UndirectedGraphNode crt = queue.poll();
                UndirectedGraphNode crtClone = map.get(crt);
                for (UndirectedGraphNode neighbor: crt.neighbors) {
                    if (map.containsKey(neighbor)) {
                        crtClone.neighbors.add(map.get(neighbor));
                    }
                    else {
                        UndirectedGraphNode newNode = new UndirectedGraphNode(neighbor.label);
                        map.put(neighbor, newNode);
                        queue.offer(neighbor);
                        crtClone.neighbors.add(newNode);
                    }
                }
            }
        }
        return newroot;
    }