HDU1811 rank of Tetris "pinch point" + "topological sort"

Source: Internet
Author: User

Rank of TetrisTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 5447 Accepted Submission (s): 1526

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)The classic problem of steamed buns, I did not do it when the game. The crux of the problem is to narrow the points equal to a point, and then the new structure of the map to sort the topology, the topological ordering process must ensure that there is a maximum of one element within the queue, otherwise it will not produce a definite sequence, in addition, if there is a ring is a conflict.

#include <stdio.h> #include <string.h> #define MAXN 10010#define maxm 20010int N, M, PRE[MAXN], Hash[maxn];int HEAD[MAXN], ID, CNT, in[maxn];bool u, c;struct Node {int U, V, Next;} E[maxm];int ufind (int k) {int a = k, B;while (pre[k]! =-1) k = Pre[k];while (A! = k) {b = pre[a];p Re[a] = K;a = b;} return k;} BOOL Same (int a, int b) {return Ufind (a) = = Ufind (b); BOOL Unite (int a, int b) {a = Ufind (a), B = Ufind (b); if (a = = B) return False;else {Pre[a] = B;return true;}}  void Getmap () {memset (Pre,-1, sizeof (int) * n), memset (head,-1, sizeof (int) * n), memset (in, 0, sizeof (int) * n), int u, V, I id = 0;char ch;for (i = 0; i < M; ++i) {scanf ("%d%c%d", &u, &ch, &v), if (ch = = ' = ') {Unite (U, v);} else if ( ch = = ' < ') {e[id].u = v; E[ID++].V = u;} else {e[id].u = u; E[ID++].V = V;}}} void Solve () {int I, J, U, V, IQ, front; u = C = 0;/* use and check set to indent points */memset (hash,-1, sizeof (int) * N); for (i = cnt = 0; i < N; ++i) {u = ufind (i); if (hash[u]! =-1 ) Hash[i] = Hash[u];else Hash[u] =Hash[i] = cnt++;} for (i = 0; i < ID; ++i) {e[i].u = hash[e[i].u]; E[I].V = hash[e[i].v];++in[e[i].v]; E[i].next = head[e[i].u];head[e[i].u] = i;} Now that the new diagram is constructed, there are a total of CNT nodes/* below to start the topology ordering when and only if the graph is a path the position may determine *///because the original hash array has been discarded, can be used when the queue to use IQ = Front = 0;for (i = 0; i < cnt; ++i) if (i N[i] = = 0) hash[iq++] = I;while (front! = IQ) {if (Iq-front > 1) U = 1;u = hash[front++];for (i = head[u]; I! =-1; i = E[i].next) {if (!--in[v = e[i].v]) hash[iq++] = V;}} if (IQ! = cnt) C = 1; With ring/* below output, C has precedence of up to */if (c) printf ("conflict\n"), else if (U) printf ("uncertain\n"), Else printf ("ok\n");} int main () {//Freopen ("Stdin.txt", "R", stdin), while (scanf ("%d%d", &n, &m) = = 2) {getmap (); Solve ();} return 0;}


HDU1811 rank of Tetris "pinch point" + "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.