#K7921. Minimum Rope Length
Minimum Rope Length
Minimum Rope Length
You are given n pegs with coordinates \((x_i, y_i)\) in the plane. Your task is to determine the minimum length of rope required to connect all pegs in a closed loop such that each peg is connected to exactly two others. The distance between any two pegs is computed by the Euclidean distance formula:
[ d(p_i, p_j) = \sqrt{(x_i - x_j)^2 + (y_i - y_j)^2} ]
You must choose an ordering of the pegs (a permutation) and compute the total length as the sum of the distances between consecutive pegs, including the distance between the last peg and the first peg to form a closed loop. Output the minimum possible total length rounded to two decimal places.
inputFormat
The first line of the input contains an integer (n), representing the number of pegs. The following (n) lines each contain two space-separated integers (x) and (y), which represent the coordinates of a peg.
outputFormat
Print a single line containing the minimum rope length required to form a closed loop connecting all pegs, rounded to two decimal places.## sample
4
0 0
2 0
2 2
0 2
8.00