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