public static UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
    	List<UndirectedGraphNode> nodes = new ArrayList<UndirectedGraphNode>();
    	UndirectedGraphNode headnode = null;
    	int index = 0;
    	if (null == node) return null;
    	nodes.add(node);
    	while (index != nodes.size()) {
    		UndirectedGraphNode n = nodes.get(index);
    		UndirectedGraphNode newNode = new UndirectedGraphNode(n.label);
    		if (null == headnode) headnode = newNode; 
    		n.neighbors.add(newNode);
    		int size = n.neighbors.size();
    		for (int i = 0; i < size - 1; i++) {
    			UndirectedGraphNode neighbor = n.neighbors.get(i);
    			if (!(nodes.contains(neighbor))) nodes.add(neighbor);
    		}
    		index = index + 1;
    	}
    	for (UndirectedGraphNode rawnode : nodes) {
    		int size = rawnode.neighbors.size();
    		UndirectedGraphNode newNode = rawnode.neighbors.get(size - 1);
    		for (int i = 0; i < rawnode.neighbors.size() - 1; i++) {
    			UndirectedGraphNode neighbor = rawnode.neighbors.get(i);
    			int neighborlen = neighbor.neighbors.size();
    			newNode.neighbors.add(neighbor.neighbors.get(neighborlen - 1));
    		}
    	}
    	for (UndirectedGraphNode rawnode : nodes) {
    		int size = rawnode.neighbors.size();
    		rawnode.neighbors.remove(size - 1);
    	}
    	return headnode;
    }