怎么做到输出所有路径后排序呢
import networkx as nx
# 建立带权图
G = nx.Graph()
# 向图中添加边,每条边都有一个权值
G.add_edge('A', 'B', weight=5)
G.add_edge('A', 'C', weight=3)
G.add_edge('A', 'D', weight=2)
G.add_edge('B', 'C', weight=1)
G.add_edge('B', 'D', weight=2)
G.add_edge('C', 'D', weight=4)
# 查找从点 A 到点 B 的所有路径
all_paths = nx.all_simple_paths(G, 'A', 'B')
for path in all_paths:
print(path)