(ugraph)
return connected_components
输入无向图ugraph
    返回一个list，list的元素是每个连通分量的节点构成的集合
输入无向图ugraph
    返回一个list，list的元素是每个连通分量的节点构成的集合
输入无向图ugraph 返回一个list，list的元素是每个连通分量的节点构成的集合
def cc_visited(ugraph):
    """
    输入无向图ugraph
    返回一个list，list的元素是每个连通分量的节点构成的集合
    """
    remaining_nodes = list(ugraph.keys())
    connected_components = []
    while len(remaining_nodes) > 0 :
        # choose the first element in remaining_nodes to be the start_node
        start_node = remaining_nodes[0]
        # use bfs_visited() to get the connected component containing start_node
        con_component = bfs_visited(ugraph, start_node)
        # update connected_components
        connected_components.append(con_component)
        # update remaining_nodes
        remaining_nodes = list(set(remaining_nodes) - con_component)
    return connected_components
def cc_visited ( ugraph ) : remaining_nodes = list ( ugraph . keys ( ) ) connected_components = [ ] while len ( remaining_nodes ) > 0 : # choose the first element in remaining_nodes to be the start_node start_node = remaining_nodes [ 0 ] # use bfs_visited() to get the connected component containing start_node con_component = bfs_visited ( ugraph , start_node ) # update connected_components connected_components . append ( con_component ) # update remaining_nodes remaining_nodes = list ( set ( remaining_nodes ) - con_component ) return connected_components