HDU 1811 rank of Tetris and search set + topological sort, improve the problem

Source: Internet
Author: User

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


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
Sometimes I feel so stupid. The last person's blog. http://972169909-qq-com.iteye.com/blog/1052820 Code:
#include <cstdio> #include <queue> #include <cstring> #define MAX 10100using namespace std; struct node{ int To,next;} Edge[2*max];int F[max], Head[max], A[2*max],b[2*max], In[max];char Ch[2*max]; bool Visited[max]; void init (int n) {for (in t i = 0; I <= N; ++i) {F[i] = i; head[i] =-1; visited[i] = false; in[i]=0;}} int find (int x) {int r=x; while (r! = F[r]) {r = F[r];} int temp = x; while (temp! = r) {x = f[temp]; F[temp] = r; temp = x;} return r;} int main () {int m, n;while (scanf ("%d%d", &n,&m)! = EOF) {init (n); int num = n; for (int i = 0; i < m; ++i) {scanf ("%d%c%d", a+i,ch+i,b+i), if (ch[i] = = ') {int fa = find (A[i]), fb = Find (B[i]), if (FA! = FB) {F[FA] = F[FB]; num--;}} int index = 0; bool flag = false; for (int i = 0; i < m; ++i) {if (ch[i] = = ') continue; int fa = Find (A[i]), FB = fin D (B[i]);//must pay attention to this, each time is directly updated to the parent node!! if (FA = = FB) {flag = true; break;} if (ch[i] = = ' > ') {bool repeat = false; for (int j = Head[fa]; J! =-1; j = edge[j].next)//Prevent heavy edges, same as {if (edge[j].to = = FB) {repeat = true; break;}} if (!repeat) {edge[index].to = fb;//is not updated on the current edge, but instead updates the parent node. Edge[index].next = Head[fa]; HEAD[FA] = index++; IN[FB] + +;}} else if (ch[i] = = ' < ') {bool repeat = false; for (int j = HEAD[FB]; J! =-1; j = edge[j].next) {if (edge[j].to = = FA) {Repe at = true; if (!repeat) {edge[index].to = Fa;edge[index].next = HEAD[FB];HEAD[FB] = index + +; in[fa]++;}}} if (flag) {puts ("CONFLICT"); continue;} Flag = False;queue<int> que; for (int i = 0; i < n; ++i) {if (in[i] = = 0 && i = = Find (i)) {Que.push (i);} }while (!que.empty ()) {if (Que.size () >1) {flag = true;} num--; int j = Que.front (); Que.pop (); visited[j] = true; for (int k = head[j]; K! =-1; k = Edge[k].next) {in[edge[k].to] --;if (!visited[edge[k].to] && in[edge[k].to]==0) {Que.push (edge[k].to);}}} if (num>0) {puts ("CONFLICT");} else if (flag) {puts ("uncertain");} Else{puts ("OK");}} return 0;}

with June

HDU 1811 rank of Tetris and search set + topological sort, improve the problem

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.