Hdu1811rank of Tetris (and 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): 5683 Accepted Submission (s): 1622


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 Problem solving: And check set: for the non-direction, so can only be used on the equal sign, and the equal sign that the equal points are equivalent, you can use a point instead of the set of equal points. That is, the shrinking point.Topology: one point is removed, if you can also remove 2 points or more points, then the information is not complete. If there is still a little to remove, then there is a ring, there is a conflict.
#include <iostream> #include <vector> #include <stdio.h> #include <string.h>using namespace std        ; const int N = 10005;int indu[n],n,fath[n],idk;vector<int>map[n];void init () {for (int i=0;i<=n;i++) {        Indu[i]=0,fath[i]=i;    Map[i].clear (); } idk=0;}    int Findfath (int x) {if (x==fath[x]) return fath[x];    Fath[x]=findfath (Fath[x]); return fath[x];}    void Setfath (int x,int y) {x=findfath (x);    Y=findfath (y); Fath[x]=y;}    void Topu () {int k=0,s[n],uncertain=0,node;        for (int i=0;i<n;i++) {if (fath[i]==i) idk++;    if (indu[i]==0&&fath[i]==i)//fath[i]==i is a point used to judge a non-equal cioed, except the final parent node, it can be regarded as the set s[k++]=i of the equal sign point;        } while (k--) {if (k>0) uncertain=1;        idk--;        NODE=S[K];            for (int i=0;i<map[node].size (); i++) {int t=map[node][i];            indu[t]--;        if (indu[t]==0) s[k++]=t; }} if (idk>0) printf ("conflict\n");    else if (uncertain) printf ("uncertain\n"); else printf ("ok\n");}    int main () {int a[n],b[n],m;    Char F[n];        while (scanf ("%d%d", &n,&m) >0) {init ();            for (int i=0;i<m;i++) {scanf ("%d%c%d", &a[i],&f[i],&b[i]);        if (f[i]== ' = ') Setfath (A[i],b[i]);            } for (int i=0;i<m;i++) if (f[i]!= ' = ') {A[i]=findfath (a[i]);            B[i]=findfath (B[i]);            if (f[i]== ' > ') {indu[b[i]]++; Map[a[i]].push_back (B[i]);            } else {indu[a[i]]++; Map[b[i]].push_back (A[i]);    }} topu (); }}


Hdu1811rank of Tetris (and 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.