import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
GFG{
static
int
N =
500
+
10
;
static
class
pair
{
double
c;
int
first, second;
pair(
double
c,
int
first,
int
second)
{
this
.c = c;
this
.first = first;
this
.second = second;
}
}
static
int
[] arr =
new
int
[N],
sz =
new
int
[N];
static
void
initialize()
{
for
(
int
i =
1
; i < N; ++i)
{
arr[i] = i;
sz[i] =
1
;
}
}
static
int
root(
int
i)
{
while
(arr[i] != i)
i = arr[i];
return
i;
}
static
void
union(
int
a,
int
b)
{
a = root(a);
b = root(b);
if
(a != b)
{
if
(sz[a] < sz[b])
{
int
tmp = a;
a = b;
b = tmp;
}
sz[a] += sz[b];
arr[b] = a;
}
}
static
double
minCost(
int
[][] p)
{
int
n = (
int
)p.length;
ArrayList<pair> cost =
new
ArrayList<>();
for
(
int
i =
0
; i < n; ++i)
{
for
(
int
j =
0
; j < n; ++j)
{
if
(i != j)
{
int
x = Math.abs(p[i][
0
] - p[j][
0
]) +
Math.abs(p[i][
1
] - p[j][
1
]);
if
(x ==
1
)
{
cost.add(
new
pair(
0
, i +
1
,
j +
1
));
cost.add(
new
pair(
0
, j +
1
,
i +
1
));
}
else
{
int
a = p[i][
0
] - p[j][
0
];
int
b = p[i][
1
] - p[j][
1
];
a *= a;
b *= b;
double
d = Math.sqrt(a + b);
cost.add(
new
pair(d, i +
1
,
j +
1
));
cost.add(
new
pair(d, j +
1
,
i +
1
));
}
}
}
}
Collections.sort(cost,
new
Comparator<>()
{
public
int
compare(pair a, pair b)
{
if
(a.c <= b.c)
return
-
1
;
else
return
1
;
}
});
initialize();
double
ans =
0.00
;
for
(pair i : cost)
{
double
c = i.c;
int
a = i.first;
int
b = i.second;
if
(root(a) != root(b))
{
union(a, b);
ans += c;
}
}
return
ans;
}
public
static
void
main(String[] args)
{
int
[][] points = { {
1
,
1
},
{
2
,
2
},
{
2
,
3
}};
System.out.format(
"%.5f"
, minCost(points));
}
}