POJ1679 Sub-niche into a tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.