Graph theory to the rescue! I’ve been reviewing some of the puzzles that I didn’t finish last year, and one of them dovetailed perfectly with this challenge, allowing me to complete it in a very reasonable amount of time (for me, at least). I think from these pair of challenges, I’ve learned a lot about practical graph stuff.

Even in my dreams, I can't win.

Even in my dreams, I can't win.

It took a long time to get the graph parsed.

Both the challenges boiled down to graph processing. Starting with a set of nodes / edges, I had to load them into a graph, then walk the graph and measure things for different challenges. Here’s the code! I’ll probably go back later and touch it up, renaming things and gleaning critical insights that every other coder learned in CS 203 (“Algorithms, Data Structures, and Deodorant; Optional?”). All joking aside, most CS students I knew were well groomed but slightly less well adjusted.