答案是具有单调性的. 因为最近的两个部落的距离为mid,所以要是有两个野人的距离<mid,则他们一定是一个部落的. 用并查集维护各联通块,如果最后的联通块个数>=k,那么mid还可以再小点.如果<k,mid还可以再大点. 二分搞一搞就行了. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector&…
BZOJ 倒序处理,就是并查集傻题了.. 并查集就是确定下一个未染色位置的,直接跳到那个位置染.然而我越想越麻烦=-= 以为有线性的做法,发现还是要并查集.. 数据随机线段树也能过去. //18400kb 2520ms #include <cstdio> #include <algorithm> typedef long long LL; const int N=1e6+5; int fa[N],col[N]; char OUT[N*10],*O=OUT; inline int F…
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the game of playing house we used to play when we are kids. What a happy time as…