hdu1811 Rank of Tetris (topological sorting + and collection)

Source: Internet
Author: User

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


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 Input
3 > < > 1 (+) > > + > (>)->

Sample Output
Okconflictuncertain

Authorlinle
Sourcehdoj Summer Exercise (2)
Recommendlcy | We have carefully selected several similar problems for you:1198 1829 1558 1856 1285
Statistic | Submit | Discuss | Note

and learned a new knowledge topology ordering

The specific is:

1 first build and then look for the vertex that reads as 0

2: Then find the edge and point associated with this vertex, delete the edge, point in the degree-1

3. Continue to search for the next vertex with a degree of 0. Repeat 2.

For the knowledge points used in this problem and check the set, topological sorting

And the check set is to handle the case of =, so that two elements merge the collection

Topological sorting processing information incomplete and conflicting

1. If there are two simultaneous degrees of 0, and the root is itself is incomplete information.

2. As for the information conflict situation is the emergence of the ring, this time will find that the query into a 0 of the loop execution is not down, that is, sum>0.

I don't have a list for this problem. The vector container is used to simulate the adjacency table. Queue implementation Topology sequencing

#include <stdio.h> #include <string.h> #include <vector> #include <queue>using namespace std; struct node//Edge {int a,b;//vertex char ch;//operator}c[10005];vector<int>map[10005];//map array storage adjacency table int N,M,SUM,IN[10005],FA [10005];//in array representation, Fa[i] represents the root node of the collection where vertex i is located int find (int x)//Find root Node {if (fa[x]!=x) Fa[x]=find (fa[x]); return fa[x];} BOOL Comb (int x,int y)//merge set {x=find (x); Y=find (y); if (x==y) return False;else{fa[y]=x;return true;}} void init ()//Initialize {for (int i=0;i<n;i++) fa[i]=i;} void Top_sort ()//queue implements topological ordering {queue<int>s;int flag=0;for (int i=0;i<n;i++) {if (in[i]==0&&fa[i]==i) S.push (i);} while (!s.empty ()) {if (S.size () >1)//Even if the discovery information is incomplete, continue to run, because if the information is incomplete and the conflict is Conflictflag=1;int Pos=s.front (); S.pop () , sum--;for (int i=0;i<map[pos].size (); i++) {in[map[pos][i]]--;if (in[map[pos][i]]==0) S.push (Map[pos][i]);}} if (sum>0) printf ("conflict\n"), else if (flag) printf ("uncertain\n"), Else printf ("ok\n");} int main () {while (scanf ("%d%d", &n,&m)!=eof) {sum=n;init (); memset (map,0,sizeof (map)); memset (In,0,sizeof (in)), for (int i=0;i<m;i++) {scanf ("%d%c%d", &c[i].a,&c[i].ch,&c[i].b), if (C[i]. ch== ' = ') {if (comb (c[i].a,c[i].b)) sum--;}} for (int i=0;i<m;i++) {if (c[i].ch== ' = ') continue;int x=find (C[I].A); int y=find (C[I].B); if (c[i].ch== ' > ') {map[x] . push_back (y); in[y]++;} Else{map[y].push_back (x); in[x]++;}} Top_sort ();}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu1811 Rank of Tetris (topological sorting + and collection)

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.