Hdu1811rank of RIS -- Conclusion report

Source: Internet
Author: User

The question is clear, but I don't know if someone is like me. At first, I was entangled in a stupid question:

0> 1, 0> 2; it should be OK, because 0 is greater than 1, 0 is greater than 2, then 1 and 2 can be ranked by character, it should be OK .... Okay, it's really a matter of IQ .. the answer is uncertain. Because we can only rank by character in the case of 1 = 2, without the description =, how can we think that the level is the same?

The detailed problem analysis is as follows:

At the very beginning, I saw it in graph theory 500. Classification is topology + and query set. It is not difficult for me to find two basic knowledge points .. Who knows... First, you should think about it, and then be careful. My solution is as follows:

1. First, let's look at the two vertices with the same level, that is, the two vertices with the '=', and in the same query set. That is to say, the points with the same level are considered as one point, it is represented by the ancestor root. If it is not processed first, it is saved with array a [I] ch [I] B [I ].

2, and then for (0 ~ M) edge, traverse once, create a directed graph with an array adjacent table, record the inbound degree, and record the number of node_num points in the new graph (here the same level is seen as a point root in a set)

3, and then start the topological sorting, so the records need to be recorded here are messy, be careful

4. First, enter the point with an inbound value of 0. (This is also the first time we use the queue + adjacent table for topology. Each time we leave a U, We Will topology it, record the number of points in the topology topo_num ++. Then, traverse the adjacent point v using the adjacent table -- this is equivalent to the delete edge operation. During the traversal process, the adjacent point v inbound degree --, if the value is 0 after the node is deleted, the number of points (Num ++) with an inbound degree of 0 will be recorded. If the value of num is greater than 1, so here the ranking is uncertain), so the above is the general method for processing topological sorting using queues + adjacent tables. We need to add a little bit in this question, when traversing the adjacent contacts using the adjacent table, we put U and V in A and check the area in the set. This is to judge whether all the points are in a set after the topology is complete.

The basic method of OK is above, so the main situation here is more complicated: when we are in conflict, when we are not sure, and when we are OK. Here I am judging from this:


OK:

# Include <iostream> # include <cstdio> # include <queue> # include <cstring> using namespace STD; # define Max 10005int n, m; int degree [Max]; // record inbound int father [Max]; // query the struct edge {int to, next;} edge [Max * 2]; int head [Max], Tol; void add (int u, int v) {edge [tol]. to = V; edge [tol]. next = head [u]; head [u] = tol ++;} int find (int x) {If (X! = Father [x]) {FATHER [x] = find (father [x]);} return father [X];} Char ch [Max]; int A [Max], B [Max]; void initmap () {for (INT I = 0; I <n; I ++) Father [I] = I; for (INT I = 0; I <m; I ++) {scanf ("% d % C % d", & A [I], & Ch [I], & B [I]); if (CH [I] = ') // put the same level in a collection {int x = find (A [I]); int y = find (B [I]); father [x] = find (y) ;}// create the Tol = 0 in step 2; memset (Head,-1, sizeof (head); memset (degree, 0, sizeof (degree )); For (INT I = 0; I <m; I ++) {int x = find (A [I]), Y = find (B [I]); if (CH [I] = '>') {Add (x, y); degree [y] ++ ;} else if (CH [I] = '<') {Add (Y, x); degree [x] ++ ;}} int TOPO () {int node_num = 0; // number of points in the new graph queue <int> q; For (INT I = 0; I <n; I ++) {If (father [I] = I) {node_num ++; If (degree [I] = 0) Q. push (I) ;}} int topo_num = 0; // number of points that pass through the topo bool unsure = false; // is there any uncertainty while (! Q. empty () {int num = 0; // during this round, the number of points with an inbound degree of 0 int u = Q. front (); q. pop (); topo_num ++; For (INT I = head [u]; I! =-1; I = edge [I]. next) {int v = edge [I]. to; degree [v] --; father [find (u)] = find (V); // merged into if (! Degree [v]) {num ++; q. push (v) ;}} if (Num> 1) unsure = true; // It indicates you are not sure} bool inaset = true; For (INT I = 0; I <N-1; I ++) {If (find (I )! = Find (I + 1) {// Analysis of the combination of the following judgments in a set of inaset = false ;}/// if (topo_num! = Node_num) return 1; else {If (inaset) {If (Unsure) return 2; else return 0;} else return 2 ;}} int main () {While (CIN> N> m) {initmap (); int ans = TOPO (); If (ANS = 1) cout <"Conflict" <Endl; else if (ANS = 2) cout <"uncertain" <Endl; else cout <"OK" <Endl ;}return 0 ;}
OK, personal ignorance. Please correct and discuss it.

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.