Given several points on a plane, let’s try to solve a puzzle connecting them with a zigzag line.
The puzzle is to find the zigzag line that passes through all the given points with the minimum number of turns. Moreover, when there are several zigzag lines with the minimum number of turns, the shortest one among them should be found.
For example, consider nine points given in Figure 10.
A zigzag line is composed of several straight line segments. Here, the rule requests that each line segment should pass through two or more given points.
A zigzag line may turn at some of the given points or anywhere else. There may be some given points passed more than once.
Two zigzag lines with three turning points are depicted in Figure 11 (a) and (b) for the same set of given points shown in Figure 10. The length of the zigzag line in Figure 11 (a) is shorter than that in Figure 11 (b). In fact, the length of the zigzag line in Figure 11 (a) is shortest so that it is the solution for the nine points given in Figure 10.
Another zigzag line with four turning points is depicted in Figure 12. Its length is shorter than those in Figure 11, however, the number of turning points is greater than those in Figure 11, and thus, it is not the solution.
There are two zigzag lines that passes another set of given points depicted in Figure 13 (a) and (b).
Both have the same number of turning points, and the line in (a) is longer than that in (b). However, the solution is (a), because one of the segments of the zigzag line in (b) passes only one given point, violating the rule.
Your job is to write a program that solves this puzzle.