2023 day 25.
This commit is contained in:
parent
57bf025622
commit
9f96abbd43
@ -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
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@
|
||||
jqt: rhn xhk nvd
|
||||
rsh: frs pzl lsr
|
||||
xhk: hfx
|
||||
cmg: qnr nvd lhk bvb
|
||||
rhn: xhk bvb hfx
|
||||
bvb: xhk hfx
|
||||
pzl: lsr hfx nvd
|
||||
qnr: nvd
|
||||
ntq: jqt hfx bvb xhk
|
||||
nvd: lhk
|
||||
lsr: lhk
|
||||
rzs: qnr cmg lsr rsh
|
||||
frs: qnr lhk lsr
|
Loading…
Reference in New Issue
Block a user