http://www.lydsy.com:808/JudgeOnline/problem.php?id=1821
The naked question.
The shortest distance of the subject requires the longest, and it is obvious that we sort.
There is greed here, that is, we give the smallest of the edge to the interior of the N tribe, and then the rest of the smallest is the answer.
Divide the edge of the edge to the K tribe, use and check the set to generate the smallest tree, so that the inner edge is always less than the edge connected to the outside. Then the remaining K points, the remaining K points of the edge must be the smallest and longest side of the tribe.
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath > #include <algorithm>using namespace std; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (I,a,n) for (in T i= (a); i<= (n) ++i) #define FOR2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n);-I.) #define FOR4 (I,a,n) for (int i= (a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define MAX (A, B) ((a) > A):(b) #define MIN (a) < (b) ( A):(B)) #define READ (a) a=getnum () #define PRINT (a) printf ("%d", a) inline int getnum () {int ret=0; char c; int k=1; for (c=g Etchar (); c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' && c<= ' 9 '; C=getchar ()) ret=ret*10+c-' 0 '; return k*ret; }const int N=1005;int x[n], y[n];struct edge {int u, V, w;bool operator < (const edge &a) Const {return w<a.w; }}e[n*n];int cnt;int f[n];int ifind (const int &x) {return x==f[x]?x:f[x]=ifind (f[x]);} int main () {int n, M;read (n); Read (m); For1 (i, 1, N) read (X[i]), read (Y[i]), For1 (i, 1, N) f[i]=i;for1 (i, 1, N) for1 (j, 1, N) if (i!=j) e[cnt].u=i, e[cnt]. V=j, e[cnt++].w= (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]); sort (e, e+cnt); int fu, Fv;for2 (i, 0, cnt) {Fu=ifind (E [I].U]; Fv=ifind (E[I].V), if (FU!=FV) {if (n>m)--n, F[fu]=fv;else {printf ("%.2lf\n", sqrt (E[I].W)); return 0;}