hdu1811 and cluster + topological sequence

Source: Internet
Author: User

Test instructions: Now there is a ranking system, there is a series of information, is the comparison of > < =, and if the final equality, will be equal to the ordinal from small to large row, asked whether the information can determine the complete sorting.

Because if many points are equal, they are sure to be able to determine the rank, so we just have to let them have the same size relationship as the other points. So we use and check the set, add the equal points and check the set, and then check the topological sequence of the cluster, if the only topological sequence can be discharged, then in each and check set inside can also have a unique order.

1#include <stdio.h>2#include <string.h>3#include <queue>4 using namespacestd;5 Const intmaxn=1e4+5;6 Const intmaxm=2e4+5;7 8 intFa[maxn],num,n;9 intA[MAXM],B[MAXM];Ten Charc[maxm][Ten]; One inthead[maxn],point[maxm],nxt[maxm],size; A intID[MAXN]; -  - voidInit () { for(intI=0; i<n;++i) fa[i]=i;} the  - intFindintx) { -     intR=x,t; -      while(R!=fa[r]) r=Fa[r]; +      while(x!=R) { -t=Fa[x]; +fa[x]=R; Ax=T; at     } -     returnR; - } -  - inttopo () { -queue<int>Q; in     BOOLf=1; -      for(intI=0; i<n;++i)if(fa[i]==i&&!Id[i]) Q.push (i); to     intCnt=0; +      while(!Q.empty ()) { -         intu=Q.front (); the Q.pop (); *cnt++; $         if(!q.empty ()) f=0;Panax Notoginseng          for(intI=head[u];~i;i=Nxt[i]) { -             intj=Point[i]; theid[j]--; +             if(!Id[j]) Q.push (j); A         } the     } +     if(Cnt!=num)return 0; -     if(f)return 1; $     return-1; $ } -  - voidAddintAintb) { thepoint[size]=b; -nxt[size]=Head[a];Wuyihead[a]=size++; theid[b]++; - } Wu  - intMain () { About     intm; $      while(SCANF ("%d%d", &n,&m)! =EOF) { -memset (ID,0,sizeof(ID)); -memset (head,-1,sizeof(head)); -Sites0; A init (); +num=N; the          for(intI=1; i<=m;++i) { -scanf"%d%s%d",&a[i],c[i],&b[i]); $             if(c[i][0]=='='){ the                 intX=find (A[i]), y=find (B[i]); the                 if(x!=y) { thefa[x]=y; thenum--; -                 } in             } the         } the          for(intI=1; i<=m;++i) { About             if(c[i][0]=='>'){ the Add (Find (A[i]), find (B[i )); the             } the             Else if(c[i][0]=='<'){ + Add (Find (B[i]), find (A[i )); -             } the         }Bayi         inttmp=topo (); the         if(tmp==1) printf ("ok\n"); the         Else if(tmp==0) printf ("conflict\n"); -         Else if(tmp==-1) printf ("uncertain\n"); -     } the}
View Code

hdu1811 and cluster + topological sequence

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.