HDU 1811 rank of Tetris "topology sort + and check set"

Source: Internet
Author: User

Since Lele developed the rating system, his Tetris career is even more powerful, and soon he has pushed 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, the output is in one row according to the topic requirement
Sample Input
7 ·
0 > 1
1 < 2
0 > 2
4 4
1 = 2
1 > 3
2 > 0
0 > 1
7 ·
1 > 0
1 > 2
2 < 1
Sample Output
Ok
CONFLICT
Uncertain
"Analysis":
1. Legitimate output OK
2. There are loops, note here, there may be equal cases, then combine the equal two numbers, then use their roots as a representation as a point, merge once, the total number of n is 1
3. Does not conform to the topological uniqueness, then the queue size when pressed into the queue >1 indicates that there are different degrees of 0 points, then mark the

"Code":

#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map> #include <cctype> #include <stack> #include <sstream> #include <list># include<assert.h> #include <bitset> #include <numeric> #define DEBUG () puts ("++++") #define GCD (A, B) _ _GCD (A, b) #define Lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_ Back#define Sqr (x) ((x) * (x)) #define MS (A, b) memset (A,b,sizeof (a)) #define SZ size () #define BE begin () #define PU push_up# Define PD Push_down#define CL Clear () #define LOWBIT (x)-x&x#define all 1,n,1#define Rep (i,n,x) for (int i= (x); i< (n) ; i++) #define in Freopen ("In.in", "R", stdin) #define OUT freopen ("Out.out", "w", stdout) using namespace Std;typedef long Long ll;typedef unsigned long long ull;typedef pair<int,int> p;const int INF = 0x3f3f3f3f;const LL LNF = 1e18;const int MAXM = 1e6 + 10;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int Dx[] = { -1,1,0,0,1,1,-1,-1};const int dy[] = {0,0,1,-1,1,-1,1,-1};const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 3  0, to, 31};const int monn[] = {0,-------+,-------------------------------------31};using namespace Std;const int MAXN 10010;const int mod = 142857;int n,m,num;queue<int> q;vector<int> g[20010];char c[20010];int inDeg[10010],        Fa[10010];int a[20010],b[20010];void Init () {for (int i=0;i<=n;i++) {fa[i]=i;    G[i].clear ();    }}int Find (int x) {if (fa[x] = = x) return x; Return Fa[x]=find (Fa[x]);}    int join (int x,int y) {int fx=find (x);    int Fy=find (y);    if (Fx==fy) return 0;    if (fx!=fy) {fa[fy]=fx; } return 1;}    void Topsort () {int ok=0; while (!q.empty ()) Q.pop ();/for (int i=0; i<n; i++) if (!indeg[i] && Find (i) ==i) Q.push (i);    When the entry is 0 and the root node is pressed into the queue while (!q.empty ()){if (q.size () >1) ok=1; int now = Q.front ();        Q.pop ();        num--;            for (int i=0;i<g[now].size (); i++) {int NXT = g[now][i];            if (--indeg[nxt] = = 0) {Q.push (NXT);    }}} if (num>0) printf ("conflict\n");    else if (OK) printf ("uncertain\n"); else printf ("ok\n");}        int main () {while (~scanf ("%d%d", &n,&m)) {init ();        memset (indeg,0,sizeof (indeg));        Num=n;            for (int i=0;i<m;i++) {scanf ("%d%c%d", &a[i],&c[i],&b[i]);                    if (c[i] = = ')//preprocessing equals condition {if (join (A[i],b[i]))//always here WA off but don't know, because only the root node is different to merge            num--;            }} for (int i=0;i<m;i++) {if (c[i]== ' = ') continue;            int X=find (a[i]);            int Y=find (b[i]);                if (c[i] = = ' > ') {g[x].push_back (y);         indeg[y]++;   } if (c[i] = = ' < ') {g[y].push_back (x);            indeg[x]++;    }} topsort (); }}

HDU 1811 rank of Tetris "topology sorting + and check set"

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.