public class Solution { public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { if(node==null) return null; Mapmap=new HashMap (); Queue que=new LinkedList (); que.add(node); map.put(node,new UndirectedGraphNode(node.label)); while(!que.isEmpty()) { UndirectedGraphNode cur=que.poll(); for(UndirectedGraphNode child:cur.neighbors) { if(!map.containsKey(child)) { map.put(child, new UndirectedGraphNode(child.label)); que.add(child); } map.get(cur).neighbors.add(map.get(child)); } } return map.get(node); }}