Objective:
Poi idea problem brush more want to brush code problem other provinces may be a bit too difficult so chose a province opened a knife, hee ' (*∩_∩*)
[HNOI2006] Highway construction problems |
At first, the grass was the wrong question.
It means that one of the most expensive roads is as small as possible, asking for the most expensive side
Language teacher has taught the largest smallest smallest of the largest is two points
The two most of the road, and then see if the first highway is enough, anyway, whatever it takes, you pick the first one and then the second one, then use and check the set to see if it's not connected. SB Problem
#include <cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<Set>#defineMAXN 10010using namespacestd;structnode{intx,y,c;};BOOLCMP (ConstNode &x,ConstNode &y) {returnx.c<y.c;} Node S1[MAXN*2],s2[maxn*2];intN,m,k;intFa[maxn];inlineintFindintx) {if(X==fa[x])returnXElse returnfa[x]=find (Fa[x]);} InlineintFindS1 (intx) { intL=1, r=m;intret=-1; while(l<=R) {intMid= (l+r) >>1; if(s1[mid].c<=x) {l=mid+1; ret=Mid;} Elser=mid-1; } returnret;} InlineintFindS2 (intx) { intL=1, r=m;intret=-1; while(l<=R) {intMid= (l+r) >>1; if(s2[mid].c<=x) {l=mid+1; ret=Mid;} Elser=mid-1; } returnret;}intMain () {//freopen ("a.in", "R", stdin); //freopen ("A.out", "w", stdout);scanf"%d%d%d",&n,&k,&M); for(intI=1; i<m;i++) { intx,y,c1,c2; scanf ("%d%d%d%d",&x,&y,&c1,&C2); Node X1; x1.x=x; X1.y=y; X1.c=C1; Node X2; x2.x=x; X2.y=y; X2.c=C2; S1[i]=x1; s2[i]=x2; } sort (S1+1, s1+m+1, CMP); Sort (S2+1, s2+m+1, CMP); intL=1;intR=30000;intret=-1; while(l<=R) {intMid= (l+r) >>1; intit1=FindS1 (mid); intIt2=finds2 (mid);intit; if(it1<k) {l=mid+1;Continue;} Else if(it1+it2<n-1) {l=mid+1;Continue;} for(intI=1; i<=n;i++) fa[i]=i;intsum=0; for(it=1; it<=it1;it++) { intXx=find (s1[it].x);intyy=find (S1[IT].Y); if(XX!=YY) {sum++; fa[xx]=yy;} } if(sum<k) {l=mid+1;Continue;} for(it=1; it<=it2;it++) { intXx=find (s2[it].x);intyy=find (S2[IT].Y); if(XX!=YY) {sum++; fa[xx]=yy;} } if(sum==n-1) {Ret=mid; r=mid-1;Continue;} Else{l=mid+1;Continue;} } printf ("%d\n", ret); return 0;}/*10 4 203 9 6 31 3 4 15 3 10 28 9 8 76 8 8 37 1 3 24 9 9 510 8 9 12 6 9 16 7 9 82 6 2 13 8 9 53 2 9 61 6 10 35 6 3 12 7 6 8 6 9 2 + 1 2*/
View Code
[Hnoi Grass]