python import networkx as nx G = nx.Graph() G.add_node("A") G.add_node("B") G.add_node("C") G.add_edge("A", "B") G.add_edge("B", "C") G.add_edge("C", "A") degree = nx.degree(G) print(degree) # {'A': 2, 'B': 2, 'C': 2} path = nx.shortest_path(G, "A", "C") print(path) # ['A', 'C'] nx.draw(G, with_labels=True)


上一篇:
下一篇:
切换中文