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

Source: Internet
Author: User

Link:

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1811

Question:

Problem description Since Lele developed the rating system, his Tetris career has become even more powerful, and 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 question contains multiple groups of tests, please process 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 requirements of the question in one row


Sample Input

3 30 > 11 < 20 > 24 41 = 21 > 32 > 00 > 13 31 > 01 > 22 < 1
 


Sample output

OKCONFLICTUNCERTAIN

Analysis:

It is also a topological sorting question, but it increases the difficulty because of an equal sign. The key to this question is how to deal with this equal sign.

The equal numbers are actually the same number. Therefore, preprocessing is required to represent all the same numbers only. Therefore, you can combine the same number into a tree using the query set, and then use the number of the root to replace all the numbers in the tree.

# Include <cstdio> # include <cstring> # include <vector> # include <queue> using namespace STD; const int n = 10005; int N, M, F [N], rank [N], X [2 * n], Y [2 * n], son [N], T; char o [2 * n]; vector <int> G [N]; void initset (int n) {for (INT I = 0; I <= N; ++ I) f [I] = I, rank [I] = 0; For (INT I = 0; I <= N; ++ I) g [I]. clear (); memset (son, 0, sizeof (son);} int find (int x) {int I, j = x; while (J! = F [J]) J = f [J]; while (X! = J) {I = f [X], F [x] = J, x = I;} return J;} bool Union (INT X, int y) {int A = find (x), B = find (y); if (a = B) {return false;} If (rank [a]> rank [B]) f [B] = A; else {If (rank [a] = rank [B]) + + rank [B]; F [a] = B ;} return true;} int main () {int U, V; char ch; while (~ Scanf ("% d", & N, & M) {initset (n); int num = N; For (INT I = 0; I <m; ++ I) {scanf ("% d % C % d", & X [I], & O [I], & Y [I]); if (O [I] = ') {If (Union (X [I], Y [I]) -- num ;}for (INT I = 0; I <m; ++ I) if (O [I]! = ') {Int x = find (X [I]), Y = find (Y [I]); If (O [I] ='> ') {G [X]. push_back (y); son [y] ++;} else {G [Y]. push_back (x); son [x] ++ ;}} queue <int> q; For (INT I = 0; I <n; ++ I) {If (son [I] = 0 & I = find (I) Q. push (I) ;}int Stan = 0; // whether it is unique while (! Q. empty () {If (Q. size ()> 1) STAN = 1; int T = Q. front (); q. pop (); -- num; For (int v = 0; v <G [T]. size (); ++ v) {If (-- Son [G [T] [v] = 0) Q. push (G [T] [v]) ;}} if (Num> 0) printf ("Conflict \ n"); else if (Stan) printf ("uncertain \ n"); else printf ("OK \ n");} return 0 ;}

-- The meaning of life is to give it meaning.

Original Http://blog.csdn.net/shuangde800 , By d_double (reprinted, please mark)

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.