HDU 1811 rank of RIS (Topology Sorting + query set)

Source: Internet
Author: User

Rank of RIS

Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 4931 accepted submission (s): 1359


Problem description
Since Lele developed the rating system, his Tetris career has become even more powerful. Soon, he pushed the game to the world.

To better suit those fans' preferences, Lele came up with a new idea: he will create a global ranking of Tetris experts, which will be updated on a regular basis and the name hall will be better than the Forbes ranking. We don't know how to rank based on rating from high to low. If two people share the same rating, then sort by the RP of these people from high to low.

Finally, Lele is about to take action and rank n people. For convenience, everyone has been numbered, from 0 to N-1, and the larger the number, the higher the RP.
At the same time, Lele obtained some (m) rating information from the paparazzi. There are three possible conditions for such information: "A> B", "A = B", and "A <B", respectively, indicating that the rating of A is higher than B and equal to B, smaller than B.

Now, Lele doesn't ask you to help him create the master list. He just wants to know whether the master list can be determined based on the information. If yes, "OK" is output ". Otherwise, determine the cause of the error, whether it is because the information is incomplete (output "uncertain") or because the information contains conflicts (output "Conflict ").
Note: If the information contains conflicts and the information is incomplete, "Conflict" is output ".

Input
This topic contains multiple groups of tests. Please process it until the end of the file.
The first line of each test contains two integers, N, and M (0 <= n <= strong, 0 <= m <= 20000), indicating the number of people to be ranked and the number of relationships obtained.
Next there are m rows, indicating the relationships respectively

Output
For each group of tests, output according to the question requirements in one row

Sample Input
3 3
0> 1
1 <2
0> 2
4
1 = 2
1> 3
2> 0
0> 1
3 3
1> 0
1> 2
2 <1

Sample output
OK
Conflict
Uncertain

 


Solution: compress the set into vertices for topological sorting, and then more set features for solving. Consider each of them as a set, and connect them together equally. Use the root node to represent the set, and then sort the topology. There is one thing to think of: they are equal, but they are compared in size, which is obviously contradictory.

Paste the Code:

 

# Include <stdio. h> # include <stdlib. h> # include <string. h ># include <queue> # define maxn 20005 using namespace STD; struct arcnode {int to; struct arcnode * Next ;}; struct arcnode * list [maxn]; int indegree [maxn], Father [maxn]; char STR [maxn]; int start [maxn], finish [maxn]; int mark1, mark2, num; void Init (int n) // initialization operation {mark1 = 0; mark2 = 0; num = N; For (INT I = 0; I <n; I ++) {FATHER [I] = I; indegree [I] = 0; List [I] = NULL ;}} int findset (INT X) // find the parent node {If (X! = Father [x]) {FATHER [x] = findset (father [x]);} return father [X];} void topological (int n) // topological sorting, use a queue to simulate {Int J, K; queue <int> q; struct arcnode * temp; For (INT I = 0; I <n; I ++) {If (indegree [I] = 0 & I = findset (I) {q. push (I) ;}} while (! Q. empty () {If (Q. size ()> 1) // only a node with a degree of 0 at a time will not have an uncertain relationship mark1 = 1; j = Q. front (); q. pop (); num --; // num is used to determine whether there is a ring temp = list [J]; while (temp! = NULL) {k = temp-> to; If (-- indegree [k] = 0) {q. push (k) ;}temp = temp-> next ;}} if (Num> 1) mark2 = 1 ;}int main () {int X, Y; int N, m, U, V; struct arcnode * temp; while (scanf ("% d", & N, & M )! = EOF) {Init (n); For (INT I = 0; I <m; I ++) {scanf ("% d % C % d ", & start [I], STR + I, & finish [I]); If (STR [I] = ') {num --; // find several independent sets X = findset (start [I]); y = findset (finish [I]); If (X! = Y) Father [y] = x ;}for (INT I = 0; I <m; I ++) {If (STR [I] = ') continue; If (STR [I] = '>') {u = findset (start [I]); V = findset (finish [I]);} if (STR [I] = '<') {u = findset (finish [I]); V = findset (start [I]);} indegree [v] ++; If (u = V) // The same set has no size but is sorted by RP, but the size is here, obviously in conflict with mark2 = 1; temp = (struct arcnode *) malloc (sizeof (struct arcnode); temp-> to = V; temp-> next = NULL; If (list [u] = NULL) lis T [u] = temp; else {temp-> next = list [u]; list [u] = temp;} topological (n); If (mark2) printf ("Conflict \ n"); else if (! Mark2 & mark1) printf ("uncertain \ n"); else printf ("OK \ n");} return 0 ;}

 

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.