#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define MAXN 2000000
using namespace std;
struct edge {
double w;
int u,v;
};
int s,p;
edge bian[MAXN];
int vis[5005][5005],x[5005],y[5005],fa[5005];
double dis(double x1,double x2,double y1,double y2) {
return sqrt(pow(x2-x1,2)+pow(y2-y1,2));
}
bool cmp(edge a,edge b) {
return a.w<b.w;
}
int find(int gu) {
if(fa[gu]==gu) {
return gu;
} else {
return fa[gu]=find(fa[gu]);
}
}
void onion(int xx,int yy) {
int xxx=find(xx);
int yyy=find(yy);
fa[xxx]=yyy;
}
int main() {
ios::sync_with_stdio(0);
cin>>s>>p;
for(int i=1; i<=p; i++) {
fa[i]=i;
}
for(int i=1; i<=p; i++) {
cin>>x[i]>>y[i];
}
int cnt=0;
for(int i=1; i<=p; i++) {
for(int j=i+1; j<=p; j++) {
bian[++cnt].w=dis(x[i],x[j],y[i],y[j]);
bian[cnt].u=i;
bian[cnt].v=j;
}
}
sort(bian+1,bian+1+cnt,cmp);
int cnt_=0;double ans=0;
for(int i=1; i<=cnt; i++) {
if(find(bian[i].u)!=find(bian[i].v)) {
onion(bian[i].u,bian[i].v);
cnt_++;
ans=max(ans,bian[i].w);
}
if(cnt_==p-s) {
cout<<fixed<<setprecision(2)<<ans;
return 0;
}
}
// for(int i=1; i<=cnt; i++) {
// cout<<bian[i].w<<" "<<bian[i].u<<" "<<bian[i].v<<"\n";
// }
}
之前的代码没有增加
ans=max(ans,bian[i].w);
这段代码 加了就可以AC 求解答