HDU 1811 Rank of Tetris (topological sort + and look-up set)

Source: Internet
Author: User
Tags printf first row

Link:

http://acm.hdu.edu.cn/showproblem.php?pid=1811

Topic:

Problem Description

Since Lele developed the rating system, his Tetris career is even more powerful, and soon he has pushed the game to the world.

In order to better match the likes of those enthusiasts, lele a new idea: he will make a global Tetris master list, regularly updated, the fame is more than the Forbes rich list also rang. 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 the RP from high to low in these several people.

Finally, Lele to start the action, to n individuals to rank. For convenience, everyone has been numbered, from 0 to N-1, and the larger the number, the higher the RP.

Meanwhile Lele got some (m) information about rating from the paparazzi. This information may have three kinds of situations, namely "a > B", "A = B", "A < B", respectively, that the rating of a is higher than B, equal to B, less than B.

Now Lele not let you to help him make this master list, he just want to know, according to this information is able to determine the master list, is the words on the output "OK". Otherwise, please judge the cause of the error, whether the information is incomplete (output "uncertain"), or because the information contains a conflict (output "CONFLICT").

Note that if the information contains conflicts and the information is incomplete, "CONFLICT" is printed.

Input

This topic contains multiple sets of tests, please handle to end of file.

The first row of each group of tests contains two integer n,m (0<=n<=10000,0<=m<=20000), representing the number of people to rank and the number of relationships they get.

And then there's M lines, which represent these relationships.

Output

For each set of tests, output on a single line according to the topic requirements

Sample Input

3 3

0 > 1

1 < 2

0 > 2

4 4

1 = 2

1 > 3

2 > 0

0 > 1

3 3

1 > 0

1 > 2

2 < 1

Sample Output

Ok

CONFLICT

Uncertain

Analysis:

is also a topological sort problem, but because of an equal sign, so added a bit of difficulty, the key is how to deal with the equal sign.

This column more highlights: http://www.bianceng.cn/Programming/sjjg/

The equal number, in fact, is the same number, so you need to preprocess, put all the same numbers, only one of them to represent, so you can use and search the set to put the same number into a tree, and then use the number of this tree root to replace all the number of the trees.

#include <cstdio> #include <cstring> #include <vector> #include <queue> using namespace std;  
const int N = 10005;  
int n,m,f[n],rank[n],x[2*n],y[2*n],son[n],t;  
Char O[2*n];  
    
vector<int>g[n];   
    void Initset (int n) {for (int i=0; i<=n; ++i) f[i]=i, rank[i]=0;  
    for (int i=0; i<=n; ++i) g[i].clear ();  
memset (son, 0, sizeof (son));  
    int find (int x) {int i,j=x;  
    while (J!=f[j]) j=f[j];  
    while (X!=J) {i=f[x], f[x]=j, x=i;  
} return J;  
    BOOL Union (int x,int y) {int a=find (x), B=find (y);  
    if (a==b) {return false;  
    } if (Rank[a]>rank[b]) f[b]=a;  
        else{if (rank[a]==rank[b]) ++rank[b];  
    F[a]=b;  
return true;  
    int main () {int u,v;  
    Char ch;  
        while (~SCANF ("%d%d", &n,&m)) {Initset (n);  
        int num=n; for (int i=0; i< m;  
            ++i) {scanf ("%d%c%d", &x[i],&o[i],&y[i]);  
            if (o[i]== ' = ') {if (Union (x[i), y[i])--num;  
            for (int i=0; i<m; ++i) if (o[i]!= ' = ') {int x=find (x[i)), Y=find (y[i));  
                if (o[i]== ' > ') {g[x].push_back (y);  
            son[y]++;  
                } else{G[y].push_back (x);  
            son[x]++;  
        }} queue<int>q;  
        for (int i=0; i<n; ++i) {if (Son[i]==0&&i==find (i)) q.push (i);  
            Whether the int stan=0;//is unique while (!q.empty ()) {if (Q.size () >1) stan=1;  
            int T=q.front ();  
            Q.pop ();  
            --num;  
            for (int v=0; v<g[t].size (); ++v) {if (--son[g[t][v]]==0) Q.push (g[t][v));  
    }    } if (num>0) printf ("conflict\n");  
        else if (STAN) printf ("uncertain\n");  
    else printf ("ok\n");  
return 0; }

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.