Skip to content

Instantly share code, notes, and snippets.

@reikoNeko
Last active December 6, 2019 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reikoNeko/8f0a21b78854621d74b618637fdbb8f8 to your computer and use it in GitHub Desktop.
Save reikoNeko/8f0a21b78854621d74b618637fdbb8f8 to your computer and use it in GitHub Desktop.
import networkx as nx
universe = nx.DiGraph()
for line in progdata:
# use elements in list directly, rather than placeholders
universe.add_edge(*line.split(')') )
paths = dict(nx.all_pairs_shortest_path_length(universe))
center = list(nx.topological_sort(universe))[0]
print(center)
total=0
for M in list(universe.nodes()):
total += paths[center][M]
print(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment