Minor cleaning 2023.

This commit is contained in:
Mikaël Capelle
2023-12-30 19:35:06 +01:00
parent d002e419c3
commit 3a9c7e728b
4 changed files with 34 additions and 21 deletions

View File

@@ -1,24 +1,20 @@
import sys
from collections import defaultdict
from dataclasses import dataclass
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
}
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)
graph = nx.Graph()
graph.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)
cut = nx.minimum_edge_cut(graph)
graph.remove_edges_from(cut)
c1, c2 = nx.connected_components(G)
c1, c2 = nx.connected_components(graph)
# part 1
answer_1 = len(c1) * len(c2)