#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 101
using namespace std;
int tr[N];
int findroot(int x)
{
if(tr[x]==-1)
return x;
else
{
int tmp=findroot(tr[x]);
tr[x]=tmp;
return tmp;
}
}
struct Edge
{
int a,b;
double cost;
bool operator < (const Edge &A) const
{
return cost<A.cost;
}
}edge[6000];
struct Point
{
double x,y;
double getDistance(Point A)
{
double tmp=(x-A.x)*(x-A.x)+(y-A.y)*(y-A.y);
return sqrt(tmp);
}
}list[N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%lf%lf",&list[i].x,&list[i].y);
int size=1;
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
{
edge[size].a=i;
edge[size].b=j;
edge[size].cost=list[i].getDistance(list[j]);
size++;
}
sort(edge+1,edge+size);
for(int i=1;i<=n;i++)
tr[i]=-1;
double ans=0.0;
for(int i=1;i<size;i++)
{
int a,b;
a=findroot(edge[i].a);
b=findroot(edge[i].b);
if(a!=b)
{
tr[a]=b;
ans+=edge[i].cost;
}
}
printf("%.2lf\n",ans);
}
return 0;
}
|