영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
Problem
Lisa is visiting an amusement park and has decided which of the N rides she wants to go on. She wants to go on each ride exactly once. For each ride, there are two equivalent facilities at different locations, i.e. 2N facilities in total. Given the positions for each facility, help Lisa plan which facility to pick for each ride and in what order she should visit them to minimize the total distance she must walk to go on all the rides.
She starts and should finish at the entrance at (0, 0).
(그림은 원문 저장소에서 볼 수 있습니다)
Figure 1: An illustration of the first sample with the optimal solution.
Input
The first line contains the integer N (1 ≤ N ≤ 15), the number of rides Lisa wants to go on. This is followed by N lines, describing each ride. One line contains four integers: the x and y coordinates of the first facility and then the x and y coordinates of the second facility. The absolute value of each coordinate is less than a million.
No facility has a position coinciding with that of another or of the entrance.
Output
The first line of the output should contain a decimal number: the minimum distance Lisa must walk. Then print N lines, each with two integers, listing the facilities she should visit. The first integer on a line should be between 1 and N and denote the ride she goes to, while the second should be 1 or 2 and denote which of the two facilities she should choose.
If there are several paths that give the same distance, you can output any one of them.
The relative or absolute error may not exceed 10^-5.
Scoring
Your solution will be tested on a set of test case groups. To get the points for a group, you need to pass all the test cases in the group.
| Group | Point value | Constraints |
|---|---|---|
| 1 | 20 | N ≤ 1 |
| 2 | 40 | N ≤ 5 |
| 3 | 40 | No additional constraints. |
예제
예제 1
3 3 5 1 -1 -2 0 0 4 4 4 0 6
14.233345 2 2 1 1 3 1