看代码就知道了。。
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<cstdio>
#include<cmath>
const int INF=0x3f3f3f3f;
typedef long long LL;
using namespace std;
const int maxn=10005;
struct Point
{
int x,y;
}P[maxn];
struct Edge
{
int s,e; //起点,终点,权值
double w;
Edge(){}
Edge(int _s,int _e,double _w):s(_s),e(_e),w(_w){}
bool operator <(const Edge &v)const{
return w<v.w;
}
};
vector<Edge> edges;
vector<int> par;
int GetRoot(int a)
{
return par[a]==a?a:par[a]=GetRoot(par[a]);
}
void init(int n)
{
for(int i=0;i<=n;i++) par.push_back(i);
}
void Merge(int a,int b)
{
int p1=GetRoot(a);
int p2=GetRoot(b);
if(p1==p2) return;
par[p2]=p1;
}
double dis(Point a,Point b)
{
return sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
int main()
{
// freopen("E:\\ACM\\test.txt","r",stdin);
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
edges.clear();par.clear();
init(N);
double w;
for(int i=1;i<=N;i++) cin>>P[i].x>>P[i].y;
for(int i=1;i<=N;i++)
{
for(int j=i+1;j<=N;j++)
{
double w=dis(P[i],P[j]);
if(w>=10&&w<=1000) edges.push_back(Edge(i,j,w));
}
}
sort(edges.begin(),edges.end()); //边权值按小到大排序
int num=0;
double ans=0;
for(int i=0;i<edges.size();i++)
{
if(GetRoot(edges[i].s)!=GetRoot(edges[i].e))
{
Merge(edges[i].s,edges[i].e);
ans+=edges[i].w;
++num;
}
if(num==N-1) break;
}
if(num!=N-1) puts("oh!");
else printf("%.1lf\n",ans*100);
}
return 0;
}