Worm Tube Space Travel
Time limit1sMemory limit256 MB
Travel between two points in 3D where movement along given segments is free and all other movement costs its Euclidean length, minimizing the paid distance.
- Level
Medium7 of 10
- Topics
- Shortest path, Geometry, Graph
- Solved
- No attempts yet
Problem
You travel from one point to another in three dimensional space. Space holds worm tubes, and each worm tube is a line segment. A traveller can enter a worm tube at any point on it and leave it at any point on it, and that movement takes no time at all. Outside a worm tube, travel time is proportional to the distance travelled.
For each test case, find the smallest distance travelled outside worm tubes on a route from the start point to the end point.
Input
The first line contains , the number of test cases.
Each test case begins with a line containing , the number of worm tubes. The next line contains the integers , and , the start point of the route. The line after that contains the integers , and , the end point.
Then follow lines. The -th of them contains six integers , , , , and , the two end points of the -th worm tube.
- Every coordinate is an integer with .
- The two end points of a worm tube are never equal.
- The start point and the end point can be the same.
Output
For each test case, print the smallest distance travelled outside worm tubes, rounded to exactly six digits after the decimal point. Print one value per line, in input order.