PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000227. Nối các hòn đảo (Island Hopping)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nối các hòn đảo (Island Hopping)

Island Hopping

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn islands with coordinates (xi,yi)(x_i,y_i). You may build straight bridges between any two islands, with cost proportional to Euclidean length. All islands must become mutually reachable through bridges.

Determine the minimum total length of bridges, where the length between two islands is (x1−x2)2+(y1−y2)2\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}.

Input

  • The first line contains integer nn.
  • Each of the next nn lines contains integer coordinates xi,yix_i,y_i for an island. All positions are distinct.

Output

Print the minimum total bridge length, with 10 digits after the decimal point.

Subtasks

  • Subtask 1 (20 points): 2≤n≤202\le n\le 20; −1000≤xi,yi≤1000-1000\le x_i,y_i\le 1000; mọi cặp tọa độ phân biệt.
  • Subtask 2 (30 points): 2≤n≤802\le n\le 80; −1000≤xi,yi≤1000-1000\le x_i,y_i\le 1000; mọi cặp tọa độ phân biệt.
  • Subtask 3 (50 points): 2≤n≤8002\le n\le 800; −1000≤xi,yi≤1000-1000\le x_i,y_i\le 1000; mọi cặp tọa độ phân biệt.

Examples

Input

3
0 0
0 3
4 0

Output

7.0000000000

Explanation

The pairwise distances are 33 between islands 1,21,2, 44 between 1,31,3, and 55 between 2,32,3. The two bridges of lengths 33 and 44 connect all islands for total length 77.