Hdoj-1811-rank of Tetris "and check set + topology Sort"

Source: Internet
Author: User

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


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)
Recommendlcy | We have carefully selected several similar problems for you:1558 1325 2647 2094 1823

#include <stdio.h> #include <string.h> #include <queue> #include <vector>using namespace std;    int f[10010],in[10010];vector<int> qu[10010];int n,m,tot;int find (int i) {if (f[i]==i) return i; Return F[i]=find (F[i]);} void Unio (int pa,int pb) {F[PA] = PB; return;} int topo () {queue<int> q;int i,ok=0,nu,tk;for (i=0;i<n;++i) {if (in[i]==0&&f[i]==i) Q.push (i);} while (!q.empty ()) {if (Q.size () >1) ok=1;//condition is insufficient int temp=q.front (); Q.pop (); tot--; Nu=qu[temp].size (); for (i=0;i< Nu;++i) {tk=qu[temp][i];//qu[temp].pop_back (); In[tk]--;if (!IN[TK]) Q.push (TK);}} if (tot>0) Ok=2;return OK;} int A[10010],b[10010];char Ch[10010];int Main () {while (~scanf ("%d%d", &n,&m)) {Tot=n;int Pa,pb,ok=0;memset (qu    , 0,sizeof (Qu)); Memset (In,0,sizeof (in));    for (int i=0;i<=n;++i) {f[i]=i;    Qu[i].clear (); }for (int i=0;i<m;++i) {scanf ("%d%c%d", &a[i],&ch[i],&b[i]),//printf ("%d#%c#%d\n", A,ch,b);p A=find (A [i]); Pb=find (B[i]); if (ch[i]== ' = ' &&pa!=pb) unIo (PA,PB), tot--;/*//written in this way, the merger and >,< judgment at the same time, here WA n times!!! if (ch[i]== ' = ' &&pa!=pb) Unio (PA,PB), tot--;if (ch[i]== ' > ') qu[pb].push_back (PA), In[pa]++;if (ch[i]== ' <    ') Qu[pa].push_back (pb), in[pb]++;*/to lump all equal nodes first together} for (int i=0;i<m;++i) {pa=find (a[i]); Pb=find (B[i]), if (ch[i]== ' > ') qu[pb].push_back (PA), In[pa]++;if (ch[i]== ' < ') Qu[pa].push_back (pb), in[pb]++;} Ok=topo (), if (ok==2) printf ("conflict\n"), else if (ok==1) printf ("uncertain\n"), Else printf ("ok\n");} return 0;}



First, we use the same point and check the merge, and then sort the topology.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj-1811-rank of Tetris "and check set + topology 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.