···11+import fileinput
22+from utils import mul
33+44+try:
55+ import networkx as nx
66+except ImportError:
77+ print("Solution requires NetworkX (`pip install networkx`)")
88+ import sys
99+ sys.exit()
1010+1111+# Parse problem input.
1212+graph = nx.Graph()
1313+1414+for line in fileinput.input():
1515+ src, rest = line.strip().split(': ')
1616+ graph.add_node(src)
1717+ for dest in rest.split():
1818+ graph.add_edge(src, dest)
1919+2020+# Solve part 1.
2121+for a, b in nx.minimum_edge_cut(graph):
2222+ graph.remove_edge(a, b)
2323+2424+print("Part 1:", mul(len(c) for c in nx.connected_components(graph)))