private void dfs(UndirectedGraphNode current, UndirectedGraphNode clone, Map<Integer, UndirectedGraphNode> map,  Set<Integer> visited) {
        if (visited.contains(current.label)) {
            return;
        }
        visited.add(current.label);
        for (UndirectedGraphNode adj : current.neighbors) {
            if (adj.label != current.label) {
                UndirectedGraphNode adjClone = map.get(adj.label);
                if (adjClone == null) {
                    adjClone = new UndirectedGraphNode(adj.label);
                    map.put(adjClone.label, adjClone);
                }
                clone.neighbors.add(adjClone);
                dfs(adj, adjClone, map, visited);
            } else {
                clone.neighbors.add(clone);
            }
        }
    }
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
https://leetcode.com/problems/clone-graph/
src/com/interview/graph/CloneGraph.java