The subject is also the smallest spanning tree that can be used with both Prime and Kruskal.
The point is that the biggest S-1 distances need to be removed because satellites can be used to cover these distances.
Tip: build a map, speed up, do not calculate on both sides.
The prime is used here because it is a dense map.
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include < limits.h> #include <algorithm>using std::sort;const int max_vec = 501;struct pos{int x, y;}; float Gra[max_vec][max_vec]; Pos pos[max_vec];float dist[max_vec];bool vis[max_vec];int N, S, P;float Prime () {memset (Vis, 0, sizeof (BOOL) * P); Vis[0] = true;for (int i = 0; i < P-1; i++) {Float m = (float) int_max;int id = 0;for (int j = 0; J < P; J + +) {if (!vis[j] & ;& Gra[0][j] < m) {m = Gra[0][j];id = j;}} Vis[id] = True;dist[i] = m;for (int j = 0; J < ID; j + +) {if (!vis[j] && gra[0][j] > Gra[j][id]) gra[0][j] = g Ra[j][id];;} for (int j = id+1; J < P; J + +) {if (!vis[j] && gra[0][j] > Gra[id][j]) gra[0][j] = Gra[id][j];}} Sort (dist, dist+p-1); return dist[p-1-s];} int main () {scanf ("%d", &n), while (n--) {scanf ("%d%d", &s, &p), for (int i = 0; i < P; i++) {scanf ("%d%d", &A mp;pos[i].x, &POS[I].Y);} for (int i = 0; i < P; i++) {for(int j = i+1; J < P; J + +) {Float A = float (pos[i].x-pos[j].x), float B = float (POS[I].Y-POS[J].Y); Gra[i][j] = sqrtf (a*a + b*b);}} printf ("%.2f\n", Prime ());} return 0;}