Tsunami
Time limit1sMemory limit128 MB
Place a warning center and connect cities with cables so every city reaches the center, no city is warned from a city farther from the shore, and total cable length is minimized.
- Level
Medium6 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Geometry
- Solved
- No attempts yet
Problem
The country of Cartesia can be described by a single Cartesian plane. The -axis is the shoreline: the upper half-plane () is land, and the lower half-plane () is ocean. Several large cities lie on the mainland, each at a position with .
From time to time a tsunami forms in the ocean near Cartesia, and the whole country can flood. The water starts at and advances uniformly in the direction of increasing .
Cartesia wants to build a tsunami warning system made of two kinds of components: a single meteorological center that can detect a tsunami far out at sea, and wired connections that carry the warning from city to city along straight line segments. (No wireless communication is allowed.)
A city is considered safe if it holds the meteorological center, or if it has a direct wired connection to another safe city. In other words, a city is safe whenever there is a multi-hop cable path from it to the meteorological center.
The time to transmit along the cables and through each city is negligible. Even so, politics complicates the engineering. If a city receives the warning over a wire from a city , and is farther from the shore than , then the residents of complain: we are closer to the ocean than , so we should have been warned first! You therefore decide to design the system so that no city ever receives the warning over a wire from a city that is farther from the shore.
Given a description of Cartesia, find the least total length of cable needed to build a tsunami warning system in which every city is safe and no city receives the warning over a wire from a city that is farther from the shore.
Input
The input may contain several test cases.
Each test case begins with a line containing an integer (), the number of cities.
Each of the next lines contains two integers and (, ), the location of one city.
The input ends with a line containing a single .
Output
For each test case, print on its own line the minimum total length of cable required to build the tsunami warning system. Print this value as a floating-point number with two digits after the decimal point.