HDU 1811 rank of Tetris and search set + topological sort

Source: Internet
Author: User
Tags in degrees

Link: http://acm.hdu.edu.cn/showproblem.php?

pid=1811

Rank of TetrisTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6539 Accepted Submission (s): 1845


Problem description Since Lele developed the rating system. His Tetris career was even more powerful, and he soon 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 say all know is based on rating from high to low row, assuming that two people have the same rating, then according to these people's RP from high to low to row.



In the end, Lele to start action. Rank n individuals. For convenience, each person has been numbered from 0 to N-1, and the higher the number, the higher the RP.


At the same time Lele get some (m) information about rating from the paparazzi. This information may be in three cases, each of which is "a > B", "A = B", "A < B". The rating of A is higher than B, which is equal to B and less than B.

Now Lele doesn't want you to help him make this list of masters. He just wants to know whether the information can be determined by the master list, yes, the output "OK." Otherwise, you can infer the cause of the error. Whether the information is incomplete (output "uncertain") or because the information includes a conflict (output "CONFLICT").


Note that if the information contains conflicts at the same time and the information is not complete, the output is "CONFLICT".



Input This topic includes several sets of tests, please handle to the end of the file.
The first line of each test group consists of 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 topic requirements
Sample Input
3 > < > 1 (+) > > + > (>)->

Sample Output
Okconflictuncertain

Practice: To use equal and check set together, to find the smallest number, that is, the number of zero in degrees. Then start the topology, the topology is every time the degree of 0, that is, the smallest number of the remaining points to take, and then to reduce its previous in degrees.


Suppose a little visit, that is to say there is a ring, explain contradictions.

Suppose that the queue has two points at the same time, indicating that the size of the two points is unclear and not understood.



#include <stdio.h> #include <vector> #include <algorithm> #include <queue>using namespace std;  int f[10010];int Find (int x) {return x==f[x]?x:f[x] = find (F[x]);} Initialize yourself void Union (int x, int y) {int fx = find (x), FY = Find (y), if (FX = = FY) return, if (fx>fy) swap (FX,FY), f[fx] = f[x] = F[y] = fy;//so that you can directly check f[i] inferred ancestors}int num[20010][2];int bi[20010];vector <int>vec[10010];int du[10010];int main () { int T;int N,m,nn,mm;char A; while (scanf ("%d%d", &n,&m)!=eof) {for (int i=1;i<=n;i++) {f[i]=i;vec[i].clear ();d u[i]=0;//in degrees 0 is the smallest}for (int j=0; j<m; j + +) {scanf ("%d%c%d", &num[j][0],&a,&num[j][1]); Num[j][0]++;num[j][1]++;if (a== ' > ') {bi[j]=1;} else if (a== ' = ') {Union (num[j][0],num[j][1]); bi[j]=0;} Else{bi[j]=-1;}} for (int j=0;j<m;j++) {if (bi[j]==1) {du[find (num[j][0])]++;vec[find (num[j][1])].push_back (num[j][0]);} else if (bi[j]==-1) {du[find (num[j][1])]++;vec[find (num[j][0])].push_back (num[j][1]);}} int Numb=0;int Sum=0;queue<int>q;while (!q.empTy ()) Q.pop (); for (int i=1;i<=n;i++)//start with the smallest {if (find (i) ==i) sum++;if (Du[find (i)]==0) {Q.push (Find (i));d u[find (i)] =-1;//said he had visited, numb++;}} int flag=0;if (q.size () >1)//Assume that there are two of the same time the queue stating that there is no size relationship between the two do not understand Flag=1;while (!q.empty ()) {int Tt=q.front (); Q.pop (); tt=  Find (TT); for (int i=0;i<vec[tt].size (); i++) {int dian=find (vec[tt][i]);d u[dian]--, if (du[dian]==0) {Q.push (dian);d u[dian]= -1;numb++;}} if (Q.size () >1) flag=1;} if (numb<sum)//If you have not visited the point is to have self-ring. Description contradiction Flag|=2;if (flag==0) puts ("OK"), else if (flag==1) puts ("uncertain"), else if (flag==2) puts ("CONFLICT"); else puts (" CONFLICT ");} return 0;}




HDU 1811 rank of Tetris and search set + topological sort

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.