马蜂有些奇怪,大佬勿喷
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 505, M = N * N;
int n, m, k, cnt, temp, X[N], Y[N], used[N], fa[N], vis[N];
struct Edge { int x, y; double z; } e[M];
bool comp(Edge x, Edge y) { return x.z < y.z; }
double dist(int i, int j) { return sqrt((double)(X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])); }
int find(int x) { return (fa[x] == x ? x : fa[x] = find(fa[x])); }
void merge(int i) {
int x = find(e[i].x), y = find(e[i].y);
if (x != y) used[ ++ temp] = i, fa[x] = y, cnt ++ ;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> k >> n;
for (int i = 1; i <= n; i ++ ) fa[i] = i, cin >> X[i] >> Y[i];
for (int i = 1; i <= n; i ++ ) for (int j = i + 1; j <= n; j ++ ) m ++ , e[m].x = i, e[m].y = j, e[m].z = dist(i, j);
sort(e + 1, e + m + 1, comp);
for (int i = 1; i <= m; i ++ ) {
merge(i);
if (cnt == n - 1) break;
}
int t, p = 0, s;
for (int i = temp; i; i -- ) {
t = 2, s = used[i];
int u = e[s].x, v = e[s].y;
if (vis[u] == 1) t -- ;
if (vis[v] == 1) t -- ;
vis[u] = vis[v] = 1;
if (p + t < k) p += t;
else if (p + t == k) { printf("%.2llf\n", e[used[i - 1]].z); break; }
else { printf("%.2llf\n", e[s].z); break; }
}
return 0;
}