开始的时候想错了,以为必须是邻接点才能使用卫星信号所以开始错了好几次!后来看了网上的说法才知道不是直接求出s-1大的边就可以了!(其实还是不明白题意)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#define INF 100000000
using namespace std;
int x[1005];
int y[1005];
int vis[1005];
int fa[1005];
struct node{
int x,y,w;
bool operator < (const node &a)const{
return w < a.w;
}
bool operator > (const node &a)const{
return w > a.w;
}
};
int fun(int x){
return fa[x] ==x ? x : fun(fa[x]);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int s,p;
cin >> s >> p;
for(int i = 0;i < p;i++){
cin >> x[i] >> y[i];
}
priority_queue<node,vector<node>,greater<node> > que;
for(int i = 0;i < p;i++){
for(int j = 0;j < p;j++){
if(i != j){
node a;
a.x = i;
a.y = j;
a.w = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
que.push(a);
}
}
}
for(int i = 0;i < p;i++){
fa[i] = i;
}
priority_queue<node,vector<node>,less<node> > ant;
while(!que.empty()){
node a = que.top();
que.pop();
int fx = fun(a.x);
int fy = fun(a.y);
if(fx != fy){
fa[fx] =fy;
ant.push(a);
}
}
memset(vis,0,sizeof(vis));
while(s > 1){
node a = ant.top();
s --;
ant.pop();
}
node a = ant.top();
printf("%.2f\n",sqrt(a.w));
}
return 0;
}