Posts

Showing posts with the label HackerRank

[HackerRank] Roads and Libraries

Image
The Ruler of HackerLand believes that every citizen of the country should have access to a library. Unfortunately, HackerLand was hit by a tornado that destroyed all of its libraries and obstructed its roads! As you are the greatest programmer of HackerLand, the ruler wants your help to repair the roads and build some new libraries efficiently. HackerLand has   cities numbered from   to  . The cities are connected by   bidirectional roads. A citizen has access to a library if: Their city contains a library. They can travel by road from their city to a city containing a library. The following figure is a sample map of HackerLand where the dotted lines denote obstructed roads: The cost of repairing any road is   dollars, and the cost to build a library in any city is   dollars. You are given   queries, where each query consists of a map of HackerLand and value of   and  . For each query, fi...