Description Cong study found that the desert Island Savage always live a gregarious life, but not the whole island of all savages belong to the same tribe, the wild people always cliques form belong to their own tribe, different tribes are often fighting. It's just that it's all a mystery-Cong doesn't know how the tribe is distributed. But the good news is that Cong got a map of the desert island. The map marks the place where N Savages Live (which can be seen as coordinates on the plane). We know that savages of the same tribe always live nearby. We defined the distance of the two tribes as the distance between the two closest settlements in the tribe. Cong also got a meaningful message-the savages were divided into K-tribes in total! That's a good news. Cong hopes to dig out the details of all the tribes from this information. He was experimenting with an algorithm that could find the distance between two tribes for any one tribe division, and Cong hoped to find a way to divide the tribe so that the nearest two tribes could be kept as far away as possible. Solution
For each edge, either within the tribe or outside the tribe, for edges with smaller sides, it should be within the tribe.
Then by the edge of the order, with Kruskal connection, until less than K connected block.
Code
1#include <cstdio>2#include <algorithm>3#include <cmath>4 #definell Long Long5 using namespacestd;6 Const intmaxn=1005;7 8 structedge{9 intu,v;Ten ll W; One BOOL operator< (Constedge&a) A Const{returnw<A.W;} -}e[maxn*MAXN]; - intX[MAXN],Y[MAXN],P[MAXN]; the intFindintx) {returnp[x]==x?x:p[x]=find (P[x]);} - intn,m,k,cnt; - -LL Dist (intAintb) { + return(LL) (X[a]-x[b]) * (X[a]-x[b]) + (Y[a]-y[b]) * (y[a]-y[b]); - } + A intMain () { atscanf"%d%d",&n,&k); - for(intI=1; i<=n;i++) -scanf"%d%d",&x[i],&y[i]); - for(intI=1; i<=n;i++) p[i]=i; - - for(intI=1; i<=n;i++) in for(intj=i+1; j<=n;j++){ -m++; toe[m].u=i,e[m].v=J; +e[m].w=Dist (i,j); - } theSort (e+1, e+m+1); * $Cnt=N;Panax Notoginseng for(intI=1; i<=m;i++){ - intA=find (e[i].u), b=find (E[I].V); the if(a!=b) { +cnt--; Ap[a]=b; the if(cnt<k) { +printf"%.2LF", sqrt (E[I].W)); - Break; $ } $ } - } - return 0; the}
Seconds. Say the recent 1 a high rate, sure enough, I brush the problem is too water?
"Minimum spanning tree + greedy" BZOJ1821: [Jsoi2010]group Tribe Division Group