Archipelago
InterviewTime limit2sMemory limit1024 MB
Given n island coordinates and a boat range d, rank each island by how many other islands are reachable through a chain of hops of length at most d.
- Level
Medium4 of 10
- Topics
- Graph, Union-find, Geometry, Sorting
- Solved
- No attempts yet
Problem
The company you work for, Boats to Get Out (BGO), has recently discovered a new archipelago, and it is an ideal spot to develop into a tourist destination. The islands are all extremely tiny, so there should be ample opportunity to base almost all transportation in the region on boats.
Unfortunately, the islands are so far out in the ocean that the standardized boat BGO provides cannot reach any of them from the mainland; the boat can hold only enough fuel to travel a distance of kilometers. To access the archipelago at all, an airport must therefore be built on one of the islands. But where should it be located?
The BGO boss has ordered you to list all the islands in order from highest to lowest airport utility. The airport utility of an island is defined as the number of islands it is possible to reach by boat from that island, using any number of intermediate stops on other islands for refuelling.
Input
The first line of input consists of two space-separated integers and , where is the number of islands and is how far a boat can travel in kilometers before it needs to refuel. The islands are named from to . The next lines of input describe the locations of the islands. The such line contains two space-separated integers and , which describe the coordinates of island .
Output
Output a single line containing space-separated integers indicating a ranking of the islands from highest to lowest airport utility. If there are multiple islands with the same utility, you may output them in any order as long as their airport utility is non-increasing.