Texas Summers
Time limit2sMemory limit256 MB
Find the route from the dormitory to class through shady spots that minimizes the sum of squared leg lengths, with ties broken by lexicographic index order.
- Level
Medium5 of 10
- Topics
- Shortest path, Graph, Geometry
- Solved
- No attempts yet
Problem
Summer in Texas gets very hot. A computer science student who has just moved there is not used to the heat, so she sweats on the walk from her dormitory to class.
The student sweats only while she is in the sun. The amount of sweat is proportional to the square of the time she has spent in the sun without a break. After seconds of unbroken sun she produces gallons, where the constant differs from student to student. Stepping into a shady spot breaks the exposure and stops the sweating at once. She rests in the shade until she has cooled off completely, and the exposure time starts again at 0 the moment she leaves the shade.
Walking speed is the same everywhere, so the sweat produced on one straight leg of length is measured as . The value of is the same for the whole walk, so it does not change which path is best.
The student walks in straight lines from the dormitory to the shady spots she chooses, in the order she chooses them, and then to class. Find a path from the dormitory to class whose total sweat is as small as possible.
Input
The first line contains the number of shady spots . ()
Each of the next lines contains two integers and , the coordinates of one shady spot. No two shady spots have the same coordinates.
Two more lines follow in the same format, giving the coordinates of the dormitory and of the class.
Every coordinate satisfies . The dormitory and the class may sit on the same point as a shady spot, and they may sit on the same point as each other.
Output
Print the indices of the shady spots the student visits, in order, one per line. Indices follow the input order and start at 0. If the path with the least sweat uses no shady spot, print a single -.
If several paths reach the minimum total sweat, print the one whose sequence of indices comes first in lexicographic order. Compare two sequences at the first position where their indices differ, and when one sequence is a prefix of the other, the shorter one comes first. So among paths with the same total, the empty path comes before every other path.