求助,WA和MLE都有。
查看原帖
求助,WA和MLE都有。
660816
Claire0918楼主2022/12/30 19:12

评测记录

#include<bits/stdc++.h>

using namespace std;

const int maxn = 500 + 10;

struct pos{
	int x, y;
};

struct edge{
	int p1, p2, d;
};

bool cmp(const edge & a, const edge & b){
	return a.d < b.d;
}

int s, p;
pos a[maxn];
int father[maxn];
int c;
double res = -1;
vector<edge> G;

inline int get_father(int x){
	return (father[x] == x) ? x : father[x] == get_father(father[x]);
}

int main(){
	scanf("%d %d", &s, &p);
	for (int i = 1; i <= p; i++){
		father[i] = i;
	}
	for (int i = 1; i <= p; i++){
		scanf("%d %d", &a[i].x, &a[i].y);
		for (int j = 1; j < i; j++){
			G.push_back({i, j, (a[i].x - a[j].x) * (a[i].x - a[j].x) + (a[i].y - a[j].y) * (a[i].y - a[j].y)});
		} 
	}
	sort(G.begin(), G.end(), cmp);
	c = p;
	for (auto x: G){
		int ti = get_father(x.p1), tj = get_father(x.p2);
		if (ti != tj){
			father[ti] = tj;
			c--;
			res = max(res, sqrt(x.d));
		}
		if (c == s){
			break;
		}
	}
	printf("%.2lf", res);

return 0;
}
2022/12/30 19:12
加载中...