Systematic salesman

아직 제출이 없습니다시간 제한6초메모리 제한256 MB

문제

A travelling salesman has received a list of cities that he must visit in a single journey. He may start and end his tour in any city as long as he visits each city at least once. He doesn’t have to start and finish in the same city. The travelling salesman noticed that his fellow travelling salesmen are spending way too much time planning and finding an optimal route. Therefore, he has decided to take a different, more systematic approach to planning his route.

He will first split all the cities into the left half and the right half. If the number of cities is odd, the right half will contain one city more than the left. He will then pick one of the halves and visit all the cities in that half before visiting any of the cities in the other half.

To visit the cities in the selected left/right half, he will split this set of cities into the lower and upper half. In case of an odd number of cities in this set, the upper half will contain an extra city. Again, he will first visit all cities in one of these halves before visiting any of the cities in the other half.

He will continue applying the same logic of alternatingly splitting the cities in half horizontally and vertically until he obtains the complete path of the journey. Compute the shortest path that visits all cities that the salesman can obtain in this way.

입력

The first line contains the number of cities NN that the salesman wants to visit. Locations of these cities are given in the NN lines that follow. The location of each city is defined by a space-separated pair of integer coordinates X_iX\_i and Y_iY\_i, which describe its location on a plane. It is guaranteed that X_iX\_i coordinates of all cities are distinct. The same holds for all Y_iY\_i coordinates.

출력

In the first line, print the minimum length of the salesman’s path. The length will be considered correct if it differs from the official solution by at most 10410^{-4}. In the second line output a space-separated list of cities as visited by the salesman. The cities are numbered from 11 to NN in order as given in the input. If there are several solutions, you can output any of them.

제한

  • 1N10001 ≤ N ≤ 1000
  • 0X_i,Y_i1060 ≤ X\_i , Y\_i ≤ 10^6

힌트

The salesman first visits the left half (cities 11, 33 and 44) and then the right half (cities 22, 55 and 66).

To visit cities 11, 33 and 44, he first visits the upper half (cities 33 and 44) before the lower half (city 11). The cities in the upper half are split into the left half (city 33), visited first, and the right half (city 44), visited afterwards.

Cities 22, 55 and 66 are split into the lower half (city 66) and the upper half (cities 22 and 55). Here, the salesman first visits the lower half. He continues his route with the upper half, where he first visits the right half (city 55) and concludes with the left half (city 22).