Perhaps should use `petgraph` crate to represent the graph, adds a bit overhead, but makes underlying algorithm and analysis clearer.