#P5143. HKE's Ascending Journey
HKE's Ascending Journey
HKE's Ascending Journey
HKE has marked (N) points on a topographic map. Each point (P_i) has coordinates ((x_i, y_i, z_i)). It is guaranteed that all altitude values (z) are distinct. HKE plans to climb from the lowest point to the highest point while satisfying the following conditions:
1. He visits every marked point.
2. Starting from the second point, each visited point has a strictly higher altitude than the previous one. In other words, if his path is (P_{i_1}, P_{i_2}, \dots, P_{i_N}), then (z_{i_1} < z_{i_2} < \cdots < z_{i_N}).
3. HKE can fly. The distance between two points (P_i) and (P_j) is defined as the Euclidean distance: (\sqrt{(x_i - x_j)^2 + (y_i - y_j)^2 + (z_i - z_j)^2}).
Your task is to compute the total climbing distance following the above conditions.
inputFormat
The first line contains an integer (N) indicating the number of points. Each of the following (N) lines contains three space-separated numbers (x_i), (y_i), (z_i) representing the coordinates of the point. It is guaranteed that no two points have the same (z) value.
outputFormat
Output a single line with the total climbing distance. The result should be printed as a floating-point number rounded to 6 decimal places.
sample
2
0 0 0
3 4 5
7.071068