(ugraph, connected_component, start_node)
return dist
返回start_node到connected_component所有节点的最短距离
返回start_node到connected_component所有节点的最短距离
返回start_node到connected_component所有节点的最短距离
def Dijkstra(ugraph, connected_component, start_node):
    '''
    返回start_node到connected_component所有节点的最短距离
    '''
    # 初始化
    minv = start_node
    visited = set()
    
    # 源顶点到其余各顶点的初始路程
    dist = dict([(node,np.float('inf')) for node in connected_component])
    dist[minv] = 0
    
    # 遍历集合V中与A直接相邻的顶点，找出当前与A距离最短的顶点
    while len(visited) < len(connected_component):
        visited.add(minv)
        # 确定当期顶点的距离
        for v in ugraph[minv]:
            if dist[minv] + 1 < dist[v]:   # 如果从当前点扩展到某一点的距离小与已知最短距离 
                dist[v] = dist[minv] + 1   # 对已知距离进行更新
        
        # 从剩下的未确定点中选择最小距离点作为新的扩散点
        new = np.float('inf')                                      
        for w in connected_component - visited:   
            if dist[w] < new: 
                new = dist[w]
                minv = w  
    return dist
def Dijkstra ( ugraph , connected_component , start_node ) : # 初始化 minv = start_node visited = set ( ) # 源顶点到其余各顶点的初始路程 dist = dict ( [ ( node , np . float ( 'inf' ) ) for node in connected_component ] ) dist [ minv ] = 0 # 遍历集合V中与A直接相邻的顶点，找出当前与A距离最短的顶点 while len ( visited ) < len ( connected_component ) : visited . add ( minv ) # 确定当期顶点的距离 for v in ugraph [ minv ] : if dist [ minv ] + 1 < dist [ v ] : # 如果从当前点扩展到某一点的距离小与已知最短距离  dist [ v ] = dist [ minv ] + 1 # 对已知距离进行更新 # 从剩下的未确定点中选择最小距离点作为新的扩散点 new = np . float ( 'inf' ) for w in connected_component - visited : if dist [ w ] < new : new = dist [ w ] minv = w return dist