import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_nodes_from([1, 2, 3, 4, 5, 6])
edges = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 6), (3, 4), (4, 5), (5, 6)]
G.add_edges_from(edges)
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True, font_weight='bold')
plt.show()
print("学号:3022")
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_nodes_from([1, 2, 3, 4, 5, 6])
edges_with_weights = [(1, 2, 7), (1, 3, 3), (1, 4, 12), (2, 3, 1), (2, 6, 1), (3, 4, 8), (4, 5, 9), (5, 6, 3)]
G.add_weighted_edges_from(edges_with_weights)
pos = {1: (0, 0), 2: (1, 1), 3: (2, 0), 4: (1, -1), 5: (-1, -1), 6: (-1, 1)}
edge_labels = nx.get_edge_attributes(G, 'weight')
nx.draw(G, pos, with_labels=True, font_weight='bold')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
plt.show()
print("学号:3022")
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_nodes_from([1, 2, 3, 4, 5, 6])
edges_with_weights = [(2, 1, 7), (1, 3, 3), (4, 1, 12), (2, 3, 1), (6, 2, 1), (3, 4, 8), (5, 4, 9), (5, 6, 3)]
G.add_weighted_edges_from(edges_with_weights)
pos = {1: (0, 0), 2: (1, 1), 3: (2, 0), 4: (1, -1), 5: (-1, -1), 6: (-1, 1)}
nx.draw(G, pos, with_labels=True, font_weight='bold', arrows=True)
edge_labels = nx.get_edge_attributes(G, 'weight')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
plt.show()
print("学号:3022")