This data comparison of water, sub-niche into a tree finally to determine whether Unicom, here is wrong, so after ...
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN = the;6 structnode7 {8     intu,v,w;9}e[maxn*MAXN];Ten intFA[MAXN],MST[MAXN]; One BOOLCMP (node A,node b) A { -     returna.w<B.W; - } the intFINDD (intx) - { -     intRT =x; -      while(RT!=FA[RT]) RT =Fa[rt]; +      while(x!=RT) -     { +         intt =Fa[x]; AFA[X] =RT; atx =T; -     } -     returnRT; - } - intMain () - { in     intT;SCANF ("%d",&T); -      while(t--) to     { +         intN,M;SCANF ("%d%d",&n,&m); -          for(inti =1; i<=m;++i) thescanf"%d%d%d",&e[i].u,&e[i].v,&E[I].W); *Sort (e+1, e+1+m,cmp); $          for(inti =1; i<=n;++i) Fa[i] =i;Panax Notoginseng         intCNT =0, W_mst =0; -          for(inti =1; i<=m;++i) the         { +             intFX = FINDD (e[i].u), FY =findd (E[I].V); A             if(FX==FY)Continue; theFA[FX] =fy; +MST[++CNT] =i; -w_mst+=E[I].W; $         } $         intFlag =1; -          for(inti =1; i<=cnt;++i) -         { the              for(intj =1; j<=n;++j) Fa[j] =J; -             intsum =0;Wuyi              for(intj =1; j<=m;++j)if(j!=Mst[i]) the             { -                 intFX = FINDD (e[j].u), FY =findd (E[J].V); Wu                 if(FX==FY)Continue; -FA[FX] =fy; Aboutsum+=E[J].W; $             } -             intOK =1; -              for(intj =2; j<=n;++j)if(fa[j]!=fa[1])//error -             { AOK =0; Break; +             } the  -             if(OK && sum==w_mst) {flag =0; Break;} $         } the         if(flag) printf ("%d\n", w_mst); the         Elseprintf"Not unique!\n"); the     } the     return 0; -}
POJ1679 Sub-niche into a tree