-
Notifications
You must be signed in to change notification settings - Fork 0
/
25.rs
35 lines (30 loc) · 881 Bytes
/
25.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#![feature(test)]
use rustc_hash::FxHashMap;
use rustworkx_core::{
connectivity::stoer_wagner_min_cut,
petgraph::{Graph, Undirected},
};
type Input = Graph<(), (), Undirected, u16>;
fn setup(input: &str) -> Input {
let mut graph = Graph::default();
let mut nodes = FxHashMap::default();
for line in input.lines() {
let p = *nodes
.entry(line.split(':').next().unwrap())
.or_insert_with(|| graph.add_node(()));
for q in line.split_whitespace().skip(1) {
let q = *nodes.entry(q).or_insert_with(|| graph.add_node(()));
graph.add_edge(p, q, ());
}
}
graph
}
fn part1(input: &Input) -> usize {
let x = stoer_wagner_min_cut(input, |_| Ok::<_, ()>(1))
.unwrap()
.unwrap()
.1
.len();
x * (input.node_count() - x)
}
aoc::main!(2023, 25, ex: 1);