2023 day 25.
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
import networkx as nx
|
||||
|
||||
lines = sys.stdin.read().splitlines()
|
||||
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
|
||||
}
|
||||
|
||||
G = nx.Graph()
|
||||
G.add_nodes_from(list(components) + list(targets))
|
||||
G.add_edges_from((u, v) for u, vs in components.items() for v in vs)
|
||||
|
||||
cut = nx.minimum_edge_cut(G)
|
||||
G.remove_edges_from(cut)
|
||||
|
||||
c1, c2 = nx.connected_components(G)
|
||||
|
||||
# part 1
|
||||
answer_1 = ...
|
||||
answer_1 = len(c1) * len(c2)
|
||||
print(f"answer 1 is {answer_1}")
|
||||
|
||||
# part 2
|
||||
|
Reference in New Issue
Block a user