Ejemplo n.º 1
0
G.add_edge(4, 7)
G.add_edge(5, 6)
G.add_nodes_from(G.nodes(), colour='never coloured')
G.add_nodes_from(G.nodes(), label=-1)
G.add_nodes_from(G.nodes(), visited='no')
dfs(G, 1)
quit()

print()
G6 = graph6.Graph()
visited_counter = 0
print('The nodes of G6 are visited by depth-first-search in this order:')
dfs(G6, 1)
print()

G7 = graph7.Graph()
visited_counter = 0
print('The nodes of G7 are visited by depth-first-search in this order:')
dfs(G7, 1)
print()

G8 = graph8.Graph()
visited_counter = 0
print('The nodes of G8 are visited by depth-first-search in this order:')
dfs(G8, 1)
print()

G9 = graph9.Graph()
visited_counter = 0
print('The nodes of G9 are visited by depth-first-search in this order:')
dfs(G9, 1)
Ejemplo n.º 2
0
            av_dist = x

    return av_dist


print()
G6 = graph6.Graph()
print(
    'The diameter of G6 (i.e. the maximum distance between two vertices) is:',
    max_distance(G6))
G6 = graph6.Graph()  # we initialize again the attributes of the graph G6
print('I found the distance between two random vertices in G6 to be:',
      random_distance(G6))
print()

G7 = graph7.Graph()
print(
    'The diameter of G7 (i.e. the maximum distance between two vertices) is:',
    max_distance(G7))
G7 = graph7.Graph()  # we initialize again the attributes of the graph G7
print('I found the distance between two random vertices in G7 to be:',
      random_distance(G7))
print()

G8 = graph8.Graph()
print(
    'The diameter of G8 (i.e. the maximum distance between two vertices) is:',
    max_distance(G8))
G8 = graph8.Graph()  # we initialize again the attributes of the graph G8
print('I found the distance between two random vertices in G8 to be:',
      random_distance(G8))