- 传送门 -
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1310
typedef double db;
const int N = 500 + 5;
struct edge {
int x, y;
db v;
}W[N*N];
int F[N], X[N], Y[N];
int cas, s, n, sz, cnt;
bool cmp (edge a, edge b) { return a.v < b.v; }
db distance(int i, int j) {
return sqrt((X[i] - X[j]) * (X[i] - X[j]) * 1.0 + (Y[i] - Y[j]) * (Y[i] - Y[j]) * 1.0);
}
void init() {
sz = cnt = 0;
for (int i = 1; i <= n; ++i)
F[i] = i;
}
int find(int x) { return x == F[x] ? x : F[x] = find(F[x]); }
void kruskal() {
for (int i = 1; i <= sz; ++i) {
int fx = find(W[i].x), fy = find(W[i].y);
if (fx == fy) continue;
cnt++;
if (cnt == s) {
printf("%.2lf
", W[i].v);
break;
}
F[fx] = fy;
}
}
int main() {
scanf("%d", &cas);
for (int i = 1; i <= cas; ++i) {
scanf("%d%d", &s, &n);
if (s >= n) {
printf("0.00
");
continue;
}
init();
for (int j = 1; j <= n; ++j) {
scanf("%d%d", &X[j], &Y[j]);
for (int k = 1; k < j; ++k) {
W[++sz].x = k; W[sz].y = j; W[sz].v = distance(k, j);
}
}
s = n - s;
sort(W + 1, W + sz + 1, cmp);
kruskal();
}
return 0;
}