Rank of Tetris
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 7961 Accepted Submission (s): 2266
Problem description Since Lele developed the rating system, his Tetris career is even more powerful, he soon all over the game to the world.
To better match the preferences of those enthusiasts, lele a new idea: he will make a global Tetris Master rankings, regular updates, more than the Forbes rich list. about how to rank, this needless to know is according to rating from high to low to row, if two people have the same rating, then according to these people's RP from high to low to row.
Finally, Lele to begin to act, ranking n individuals. For convenience, everyone has been numbered, from 0 to N-1, and the larger the number, the higher the RP.
Meanwhile Lele obtained some (m) information about rating from the paparazzi. This information may have three cases, namely "a > B", "A = B", "A < B", respectively, that the rating of a is higher than B, equal to B and less than B.
Now Lele not let you to help him make this master list, he just want to know, according to whether this information can determine the master list, yes, the output "OK". Otherwise, you can determine the cause of the error because the information is incomplete (output "uncertain"), or because the information contains a conflict (output "CONFLICT").
Note that if the information contains both conflicting and incomplete information, the output is "CONFLICT".
Input This topic contains multiple sets of tests, please handle to the end of the file.
The first row of each group of tests contains two integers n,m (0<=n<=10000,0<=m<=20000), each representing the number of people to rank and the number of relationships received.
Next there are m lines, which represent these relationships
Output for each set of tests, in one row according to the requirements of the issue
Sample INPUT3 > < > All-in-one > 1 > + > (>) > (<)
Sample Outputokconflictuncertain did not expect to use topological sort = = also use the kind and look up the set to find the relationship. The problem is to use the same point and check the set into a point, and then judge the conflict is to determine whether the relationship between the ring or < > is in the same set, to determine whether the information is exactly the only one to determine whether each time the point is 0.
#include <stdio.h>#include<algorithm>#include<string.h>#include<queue>using namespacestd;Const intN =10005;intn,m;intFather[n];intIndegree[n];structnode{intb; Chars;} node[2*N];structedge{intU,v,next;} edge[2*N];intHead[n];int_find (intx) { if(X!=father[x]) father[x] =_find (father[x]); returnfather[x];}voidUnion (intAintb) { intx =_find (a); inty =_find (b); if(x==y)return ; FATHER[X]=y;}voidAddedge (intUintVint&k) {edge[k].u= U,EDGE[K].V =v; Edge[k].next= head[u],head[u]=k++;}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) { for(intI=0; i<n;i++) {Father[i]=i; Head[i]= -1; Indegree[i]=0; } BOOLFlag =true, Flag1 =true;///Flag judgment Conflict, Flag1 judgment integrity intCNT =N; for(intI=0; i<m;i++) {scanf ("%d%c%d",&node[i].a,&node[i].s,&node[i].b); if(node[i].s=='=') {Union (node[i].a,node[i].b); CNT--; } } inttot =0; for(intI=0; i<m;i++){ Chars =Node[i].s; intA = Node[i].a,b =node[i].b; intx =_find (a); inty =_find (b); if(s!='='&&X==Y) flag =false; if(s=='<') {Indegree[x]++; Addedge (Y,x,tot); } if(s=='>') {Indegree[y]++; Addedge (X,y,tot); }} Queue<int>Q; for(intI=0; i<n;i++){ if(indegree[i]==0&&father[i]==i) {Q.push (i); } } while(!Q.empty ()) { intt =Q.front (); Q.pop (); CNT--; if(!q.empty ()) Flag1 =false;///There are multiple points with an entry level of 0, the answer is not unique for(intK = head[t];k!=-1; k=Edge[k].next) { intv =edge[k].v; INDEGREE[V]--; if(indegree[v]==0) Q.push (v); } } if(cnt>0) flag =false; if(!flag) printf ("conflict\n"); Else if(!FLAG1) printf ("uncertain\n"); Elseprintf"ok\n"); } return 0;}
HDU 1811 (topology sort + and check set)