http://acm.hdu.edu.cn/showproblem.php?pid=1811
Rank of Tetris
problem Descriptionsince Lele developed the rating system, his Tetris career is even more powerful, and soon he has pushed 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".
InputThis 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
Outputfor each set of tests, the output is in one row according to the topic requirement
Sample Input3 30 > 11 < 20 > 24 41 = 21 > 32 > 00 > 13 31 > 01 > 22< 1
Sample OutputOKCONFLICTuncertain
1#include <cstdio>2#include <algorithm>3#include <cstring>4#include <iostream>5#include <queue>6 using namespacestd;7 #defineN 100108 intx[n*2],y[n*2];9 Charch[n*2][3];Ten intFa[n],deg[n]; One intF1,f2,tot; A structnode - { - intnext,to; the}edge[n*2]; - inthead[n],n,m,cnt; - /* - and check set + topology sorting + because there is an equal condition, put the equal condition in a set, when the topological sort - sort all the elements in the collection using only one root in that set. + The rest is the topological sort of content: A If there is a loop, then the number of points in the queue (0 after the update) is <n, at It is important to note that in the case of equals, it is also considered a point. - The case of relationship determination is that every time you join a team, it will only enter a zero-in point. - */ - voidInit () - { -F1=f2=1;//f1 = confict, F2 = Uncertain intot=0; -Cnt=0; tomemset (deg,0,sizeof(deg)); +memset (head,-1,sizeof(head)); - for(intI=0; i<n;i++){ thefa[i]=i; * } $ }Panax Notoginseng - intFind (intx) the { + if(X==fa[x])returnx; A returnfa[x]=Find (fa[x]); the } + - voidMerge (intXinty) $ { $ intFx=find (x), fy=Find (y); - if(fx!=FY) { -fa[fx]=fy; the } - }Wuyi the voidAddintUintv) - { Wuedge[tot].to=v; -edge[tot].next=Head[u]; Abouthead[u]=tot++; $ } - - voidTopper () - { Aqueue<int>que; + while(!que.empty ()) Que.pop (); the for(intI=0; i<n;i++){ - if(deg[i]==0&&fa[find (i)]==i) { $ Que.push (i); thecnt++; the } the } the while(!Que.empty ()) { - inttop=Que.front (); Que.pop (); in if(!que.empty ()) f2=0; the for(intk=head[top];~k;k=Edge[k].next) { the intv=edge[k].to; Aboutdeg[v]--; the if(deg[v]==0){ the Que.push (v); thecnt++; + } - } the }Bayi if(cnt<n) f1=0; the } the - intMain () - { the while(~SCANF ("%d%d",&n,&m)) { the init (); the for(intI=0; i<m;i++){ thescanf"%d%s%d",&x[i],ch[i],&y[i]); - if(ch[i][0]=='='){ thecnt++; the Merge (X[i],y[i]); the }94 } the for(intI=0; i<m;i++){ the if(ch[i][0]=='=')Continue; the intFx=find (X[i]), fy=Find (Y[i]);98 if(fx==fy) f1=0; About if(ch[i][0]=='<'){ - Add (fx,fy);101deg[fy]++;102 }103 Else{104 Add (FY,FX); thedeg[fx]++;106 }107 }108 topper ();109 if(f1==1&&f2==1) cout<<"OK"<<Endl; the Else if(f1==0|| f1==0&&f2==0) cout<<"CONFLICT"<<Endl;111 Elsecout<<"uncertain"<<Endl; the }113 return 0; the}
HDU 1811:rank of Tetris (and set + topology sort)