Airport Logistics
Time limit2sMemory limit512 MB
Find the minimum travel time from A to B when moving at speed 1 m/s on the floor and 2 m/s along straight conveyor segments that can be entered or left at any point.
- Level
Medium7 of 10
- Topics
- Shortest path, Geometry, Graph, Math
- Solved
- No attempts yet
Problem
Many airports have moving walkways in the corridors between halls and terminals. Instead of walking on the floor, a passenger can stand on a walkway, and walking along one gets you to the end of the corridor much faster.
Delft City Airport uses the same idea. Following the latest fashion in airport architecture, it has no corridors at all. The whole airport is one big hall, and the conveyors lie on the floor at arbitrary positions and in arbitrary directions.
To get from a point to a point , a passenger may mix walking on the floor and walking on conveyors any way they like. You can hop on or off a conveyor at any point along it, and you can cross a conveyor without standing on it.
Walking on the floor goes at 1 meter per second. Walking forward on a conveyor goes at a total speed of 2 meters per second.
Walking against the direction of a conveyor gains nothing and is forbidden, but you may walk on the floor immediately next to a conveyor. Conveyors are infinitely thin.
Find the minimum time needed to get from to .

Figure 1: the fastest route for the first sample input.
Input
The first line contains four floating point numbers , , , . The start is and the destination is .
The second line contains an integer , the number of conveyors in the hall (). Each of the following lines contains four floating point numbers , , , . That conveyor starts at , ends at , and runs in a straight line from its start to its end.
All coordinates are floating point numbers in meters with .
Every conveyor is at least 1 meter long. No two conveyors intersect or touch. Neither the start nor the destination lies on a conveyor.
Output
Print on one line the minimum time in seconds needed to get from to , rounded to six digits after the decimal point.
The judge compares your output as text, so compute the time accurately enough that the sixth digit is right.