aoc/23/day25/main.py

22 lines
461 B
Python
Raw Normal View History

2023-12-25 12:51:14 +00:00
#!/usr/bin/env python3
import networkx as nx
G = nx.Graph()
with open("input.txt", "r") as f:
for line in f:
pieces = line.strip().split(": ")
start = pieces[0]
for end in pieces[1].split(" "):
G.add_edge(start, end)
cut_edges = nx.minimum_edge_cut(G)
G.remove_edges_from(cut_edges)
part1 = 1
for subgraph in (G.subgraph(c) for c in nx.connected_components(G)):
part1 *= subgraph.number_of_nodes()
print(part1)