Maximum Detour
Time limit1sMemory limit128 MB
Given the vertices of a polygonal path in order, compute the largest ratio of along-path length to straight-line distance over all vertex pairs.
- Level
Medium4 of 10
- Topics
- Geometry, Brute force, Prefix sum
- Solved
- No attempts yet
Problem
The geometric graph in this problem is a path of vertices , with one edge joining and for every with . Each vertex is a point on the plane, and each edge is the straight segment between the two points it joins.
Read as a road network you may travel only along its edges. Getting from one vertex to another is then usually longer than the straight line between them, and the detour is the ratio of the two. For two vertices and with ,
where is the Euclidean distance between two points and , and is the length of the walk along the path. The maximum detour is the largest detour over all pairs of distinct vertices of .

The figure shows a geometric graph that is a path of 7 vertices . The numbers are Euclidean distances between pairs of vertices, so and . Here .
You are given the points of one such path in order. Compute the maximum detour .
Input
The first line has the number of test cases (). Each test case begins with a line holding the number of vertices (), followed by lines holding the coordinates of in that order, one vertex per line. The two integers on a line are separated by one space. Every coordinate is an integer between and . No two consecutive vertices are the same point, so every edge has positive length.
Output
Print one line for each test case.
If is at least 1000, print TOO LARGE. Otherwise print rounded to two digits after the decimal point, always writing both digits: print 1.00, not 1.
The path may cross itself. Two vertices that are not neighbours may even lie on the same point, and then the distance between them is 0 and grows without bound, so the answer is TOO LARGE.
In every test case the exact value of is farther than from 1000, and farther than from any value halfway between two multiples of 0.01 such as 0.005, 0.015 or 0.025. The rounding direction is never ambiguous.