Tivoli
InterviewTime limit1sMemory limit1024 MB
Pick one facility per attraction and an visiting order that gives the shortest closed walk from the origin, with N up to 15.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem

The image shows the first sample case and one optimal solution.
Lisa has arrived at the amusement park and has chosen attractions to ride. Each attraction has two identical facilities, so there are facilities in total. She rides each attraction exactly once. Given the positions of all facilities, choose which facilities to visit and the order in which to visit them so that the total distance Lisa walks is as short as possible. She starts at the entrance and must return there. The entrance is at the origin.
Input
The first line contains an integer (), the number of attractions. The next lines describe attractions to in order. Each line contains four integers: the x and y coordinates of the first facility, followed by the x and y coordinates of the second facility. The absolute value of every coordinate is less than one million.
No facility is at the same position as another facility, and no facility is at the origin.
Output
The first line contains the distance Lisa walks as a real number. Then print lines, each with two integers. The first integer is the attraction number ( to ) that Lisa visits, and the second is the facility number ( or ) she uses for it.
If several routes give the same shortest distance, print any of them. Reversing a route gives the same distance, so there are always at least two valid answers. The relative or absolute error must be less than .