Dig or Climb
Time limit8sMemory limit512 MB
Given a polyline terrain cross-section, find the shortest travel time from the first point to the last, walking along the surface or tunneling horizontally between two same-height points whose interior stays below the terrain.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Geometry, Implementation
- Solved
- No attempts yet
Problem
Benjamin Forest VIII is the king of a country. His close friend Nod lives in a village far from the castle. Nod falls seriously ill and his life is in danger, so the king orders his subordinate Red to deliver good medicine as fast as possible. There is no road from the castle to the village, so Red has to climb over mountains and cross canyons to reach it.
Red travels along the shortest path on the map, the straight line between the castle and the village. The cross section of the terrain along that line is a polyline through the points .

Figure 1. An example route from the castle to the village
is the horizontal distance from the castle to point , and is the height of point . The castle is at and the village is at .
Red walks on the surface at speed . He also has a skill that cuts a horizontal tunnel through a mountain, and he moves inside a mountain at speed .
Red has two ways to move. The first is walking along the polyline, either to the left or to the right. That takes the length of the walked part of the polyline divided by . The second is digging through a mountain. If two points and on the polyline have the same height, , and the terrain height is greater than at every with , then Red can move between the two points along the horizontal line. That takes . If the terrain height is at most anywhere strictly between the two points, that stretch is not inside a mountain and cannot be dug.
Write a program that computes the minimum time to reach the village.
Input
The input is a sequence of datasets. Each dataset has the following format.
n
vw vc
x1 y1
...
xn yn
The first line holds the number of points . The second line holds the walking speed and the digging speed . Each of the next lines holds the coordinates and of one point.
, , , and whenever . Every value in the input is an integer.
The input ends with a line that holds in place of . That line is not a dataset and must not be processed.
Output
For each dataset, print the minimum time to reach the village on its own line. Round the value to six digits after the decimal point and print all six digits. Print no other character and no extra space.