Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import networkx as nx
- def solve(data):
- lines = [i.split(")") for i in data.splitlines()]
- G = nx.Graph()
- nodes = set()
- for line in lines:
- G.add_edge(line[0], line[1])
- G.add_edge(line[1], line[0])
- nodes.add(line[0])
- nodes.add(line[1])
- total = 0
- for each in nodes:
- total += nx.shortest_path_length(G, "COM", each)
- print("Part1", total)
- print("Part2", nx.shortest_path_length(G, "YOU", "SAN")-2)
- solve(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement