def Search_low(name): #cost为到该点的总价格 #cost=costs[name] #把要查的节点name的邻居全拿出来 newcost=[] for son in graph[name]: #newcost=哈希表中相邻的价格 if (son not in used) and (son not in faused): newcost.append(graph[name][son]) print(son,"son666") #找到最小花费的儿子 newcost.sort() if(len( newcost )): tool=newcost.pop(0) else: return None for son in graph[name]: if tool==graph[name][son]: return son def Search(name): #查花费最少的son B father=Search_low(name) #循环开始 while father not in faused : name=father for son in graph[name].keys(): newson=Search_low(father) if newson ==None: break newcost=graph[father][newson] if newcost + costs[father] < costs[newson]: costs[newson]=newcost + costs[father] parents[newson]=father used.append( newson ) used.clear() faused.append(father) father = Search_low( name ) for newfather in graph.keys(): if newfather not in faused and newfather!="start": father =newfather break if father==None: break
05-20
1630
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)