How to solve "Roads and Libraries" on HackerRank

T his challenge boils down to a route finding problem: starting from any city with a library, what’s the least number of roads we need to travel we need to travel to get to any other city that can be reached by road. It has the minor complications that we need to group cities into clusters that are all reachable from each other, and decide where in that cluster to build libraries, but those are…