re三点,求助
查看原帖
re三点,求助
1073955
wuchenye楼主2024/7/29 10:45
#include<bits/stdc++.h>
using namespace std;
const int N=510,M=250010;
int fa[N],a[N],b[N],k,n,tot,cnt;
double ans;
struct node {
	int x,y;
	double z;
} stu[M];
bool operator < (const node &A,const node &B) {
	return A.z<B.z;
}
int find(int x) {
	if(x==fa[x]) return x;
	fa[x]=find(fa[x]);
}
void merge(int x,int y) {
	int r1=find(x),r2=find(y);
	fa[r1]=r2;
}
int main() {
	cin>>k>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i]>>b[i];
		for(int j=1; j<i; j++) {
			stu[++tot].z=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
			stu[tot].x=i,stu[tot].y=j;
		}
	}
	for(int i=1; i<=n; i++) {
		fa[i]=i;
	}
	sort(stu+1,stu+tot+1);
	for(int i=1; i<=tot; i++) {
		if(find(stu[i].x)!=find(stu[i].y)) {
			merge(stu[i].x,stu[i].y);
			ans=stu[i].z;
			if(++cnt>=n-k) break;
		}
	}
	printf("%.2lf", ans);
	return 0;
}//c++代码re了
2024/7/29 10:45
加载中...