最短路变形。。
#include "stack"
#include "cstdio"
#include "iostream"
#include "cmath"
#include "set"
#include "sstream"
#include "cctype"
#include "string"
#include "cstring"
#include "algorithm"
#include "queue"
using namespace std;
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
const int M=1005;
double map[M][M],vis[1100],dis[1100];
int ant,n,m;
double a[1000],b[1000],c,d;
double prim(int t)
{
int i,j,k;
memset(vis,0,sizeof(vis));
vis[t]=1;
for(i=0;i<n;i++)
{
dis[i]=map[i][0];
}
vis[0]=1;
if(t==0)
{
for(i=0;i<n;i++)
{
dis[i]=map[i][1];
}
vis[1]=1;
}
double s=0;
for(j=1;j<n-1;j++)
{
double minn=inf;
for(i=0;i<n;i++)
{
if(!vis[i]&&minn>dis[i])
{
minn=dis[i];
k=i;
}
}
vis[k]=1;
s+=minn;
for(i=0;i<n;i++)
{
if(!vis[i]&&dis[i]>map[k][i])
dis[i]=map[k][i];
}
}
return s;
}
int main()
{
int i,j;
int t;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
map[i][i]=0;
for(j=0;j<=i;j++)
{
map[i][j]=map[j][i]=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
}
}
d=inf;
for(i=0;i<n;i++)
{
c=prim(i);
d=min(c,d);
}
printf("%.2lf\n",d);
}
}