At first it was wrong to think that it must be the adjacency point to use the satellite signal, so it started wrong several times! Later read the online statement just know not directly to find out s-1 big side on it! (actually still don't understand test instructions)
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector># Include <cstring> #define INF 100000000using namespace Std;int x[1005];int y[1005];int vis[1005];int fa[1005]; struct Node{int X,y,w;bool operator < (const node &a) Const{return W < A.W;} BOOL operator > (const node &a) Const{return w > a.w;}}; int fun (int x) {return fa[x] ==x x:fun (fa[x]);} int main () {int t;scanf ("%d", &t), while (t--) {int s,p;cin >> s >> p;for (int i = 0;i < p;i++) {cin >> X[i] >> y[i];} priority_queue<node,vector<node>,greater<node> > que;for (int i = 0;i < p;i++) {for (int j = 0;j < P; J + +) {if (i! = j) {Node a;a.x = I;A.Y = J;A.W = (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]); Que.push (a);}}} for (int i = 0;i < p;i++) {Fa[i] = i;} Priority_queue<node,vector<node>,less<node> > Ant;while (!que.empty ()) {Node A = Que.top (), Que.pop (), int fx = Fun (a.x), int fy = fun (A.Y); if (FX! = FY) {FA [FX] =fy;ant.push (a);}} memset (vis,0,sizeof (VIS)); while (S > 1) {Node A = Ant.top (); s--;ant.pop ();} Node A = Ant.top ();p rintf ("%.2f\n", sqrt (A.W));} return 0;}
UVA 10369 section K edge on Arctic Network minimum spanning tree