26 lines
547 B
Python
26 lines
547 B
Python
import sys
|
|
|
|
import networkx as nx
|
|
|
|
components = {
|
|
(p := line.split(": "))[0]: p[1].split() for line in sys.stdin.read().splitlines()
|
|
}
|
|
|
|
targets = {t for c in components for t in components[c] if t not in components}
|
|
|
|
graph = nx.Graph()
|
|
graph.add_edges_from((u, v) for u, vs in components.items() for v in vs)
|
|
|
|
cut = nx.minimum_edge_cut(graph)
|
|
graph.remove_edges_from(cut)
|
|
|
|
c1, c2 = nx.connected_components(graph)
|
|
|
|
# part 1
|
|
answer_1 = len(c1) * len(c2)
|
|
print(f"answer 1 is {answer_1}")
|
|
|
|
# part 2
|
|
answer_2 = ...
|
|
print(f"answer 2 is {answer_2}")
|