human
I am working on the file "04_BFS.ipynb".
The first task is:
Clone Graph

http://www.lintcode.com/en/problem/clone-graph/
https://leetcode.com/problems/clone-graph/#/description
Can you write Python program for it?
assistant
#Here is the Python program you requested.

# Definition for a undirected graph node
# class UndirectedGraphNode:
#     def __init__(self, x):
#         self.label = x
#         self.neighbors = []
class Solution:
    # @param node, a undirected graph node
    # @return a undirected graph node
    def __init__(self):
        self.dict = {}
        
    def cloneGraph(self, node):
        # write your code here
        if node is None:
            return 
        
        nodeCopy = UndirectedGraphNode(node.label)
        self.dict[node] = nodeCopy
        
        queue = [node]
        while queue:
            node = queue.pop(0)
            for n in node.neighbors:
                if n not in self.dict:
                    nc = UndirectedGraphNode(n.label)
                    self.dict[n] = nc
                    self.dict[node].neighbors.append(nc)
                    queue.append(n)
                else:
                    self.dict[node].neighbors.append(self.dict[n])
        
        return nodeCopy