http://acm.hdu.edu.cn/showproblem.php?pid=1162
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const int N=110;
const int MaxDist=INT_MAX;
struct node
{
double x,y;
}s[N];
double mat[N][N],dist[N];
bool visit[N];
int n;
void prim()
{
double sum=0,carry1;
int i,j,carry2;
for(i=0;i<n;i++)
{
dist[i]=mat[i][0];
visit[i]=false;
}
visit[0]=true;
for(i=0;i<n;i++)
{
carry1=MaxDist;
for(j=0;j<n;j++)
{
if(carry1>dist[j]&&visit[j]==false)
{
carry1=dist[j];
carry2=j;
}
}
if(carry1==MaxDist)break;
visit[carry2]=true;
sum+=carry1;
for(j=0;j<n;j++)
{
if(dist[j]>mat[carry2][j]&&visit[j]==false)
{
dist[j]=mat[carry2][j];
}
}
}
printf("%.2lf\n",sum);
}
int main()
{
int i,j;
while(cin>>n)
{
for(i=0;i<n;i++)
{
cin>>s[i].x>>s[i].y;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
double x=s[i].x-s[j].x,y=s[i].y-s[j].y;
mat[i][j]=sqrt(x*x+y*y);
}
}
prim();
}
return 0;
}