aoc/23/day25/main.py
2023-12-25 13:51:14 +01:00

21 lines
461 B
Python
Executable file

#!/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)