6,10

import networkx as nx
import numpy as np
Adjt = [(1,2,20), (1,5,15), (2,3,20), (2,4,60), (2,5,25), (3,4,30), (3,5,18), (5,6,15)]
G = nx.Graph()
G.add_nodes_from(range(1, 7))
G.add_weighted_edges_from(Adjt)
dis = nx.floyd_warshall_numpy(G)
max_dis = np.max(dis, axis=1)
min_max_dis = np.min(max_dis)
ind = np.argmin(max_dis) + 1
print(dis)
print("最小值为:", min_max_dis)
print("最小值的地址为:", ind)
nx.draw(G, with_labels=True, font_color='w')

posted @ 2024-10-27 23:58  世梦  阅读(19)  评论(0)    收藏  举报