First we can consider the two-point answer + greed.
Each check combines a point pair with all edge weights smaller than mid to one and check the set.
Then we analyze the correctness of this and find that whenever mid gets bigger, the number of tribes decreases and it is monotonous.
But with this as a basis.
We can extend to the idea of iteration, and then ...
Then consider that if each tribe, then the answer must be the smallest side of all the edges,
And if we're merging some tribes, we're going to cause some edges to be deleted.
(Note: Merging two tribes, then the deleted edge is not necessarily the only one of the two tribes, this is too water, not elaborate)
At this point the answer is the smallest edge in all sides.
So obviously-the answer must be in the smallest spanning tree.
This one's own brain mend soon come out.
So we can create a minimal spanning tree, then record the tree edge, then O (1) can be solved.
Now Analyze This O (1) is how an O (1)!
There are n individuals, M tribes, then the original minimum spanning tree n-1, the new minimum spanning tree m-1 edge, that is, the deletion of N-m edge
So the first n-m+1 edge of the smallest spanning tree is the answer.
Code:
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #define N 1050#define Inf 0x3f3f3f3fusing namespace Std;int n,m,x[n],y[n],cnt;struct road{int U,v,len;bool operator < (const ROAD &a) con St{return Len<a.len;} ROAD (int _u,int _v,int _len): U (_u), V (_v), Len (_len) {}road () {}}road[n*n];int f[n],id;int find (int x) {if (f[x]==x) return X;return F[x]=find (f[x]);} int main () {//freopen ("test.in", "R", stdin),//freopen ("My.out", "w", stdout), int i,j;scanf ("%d%d", &n,&m); for (i=1;i<=n;i++) scanf ("%d%d", &x[i],&y[i]); for (i=1;i<=n;i++) {f[i]=i;for (j=i+1;j<=n;j++) road[++id ]=road (I,j, (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]);} Sort (road+1,road+id+1); M=n-m;for (i=1;i<=id;i++) {int Fu=find (ROAD[I].U), Fv=find (ROAD[I].V), if (FU==FV) continue ; F[fv]=fu;if (++cnt>m) {printf ("%.2lf\n", sqrt (Road[i].len)); return 0;}} return 0;}
"BZOJ1821" "JSOI2010" group Tribe Division Group (two group What do you mean