#include<bits/stdc++.h>
using namespace std;
long long x[5005], y[5005];
int n, vis[5005];
long long mp[5005][5005];
long long d[5005];
long long prim() {
for (int i = 1; i <= n; i++) vis[i] = 0, d[i] = 9e18; //初始化
long long ans = 0;
for (int i = 1; i <= n; i++) {
int t = -1;
for (int j = 1; j <= n; j++) {
if (vis[j] == 0 && (t == -1 || d[j] < d[t])) t = j;
}
vis[t] = 1; //标记
if (i > 1)
ans =
max(ans, d[t]); // ans += d[t]; //第一个点不加,i==1是d[t]=1e9
for (int j = 1; j <= n; j++)
d[j] = min(d[j], mp[t][j]); //二维数组注意空间复杂度
}
return ans;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &x[i], &y[i]);
}
int index = 0;
for (int i = 1; i <= n; i++) {
mp[i][i] = 0;
for (int j = i + 1; j <= n; j++) {
mp[i][j] = mp[j][i] = (x[i] - x[j]) * (x[i] - x[j]) +
(y[i] - y[j]) * (y[i] - y[j]);
}
}
cout << prim() << endl;
}
return 0;
}
杭电签到补题
最新推荐文章于 2023-07-30 16:07:39 发布