Topological sequencing-and check set-Rank of Tetris

Source: Internet
Author: User

Description

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

3 > < > 1 (+) > > + > (>)->

Sample Output

Okconflictuncertain


--------------------------------------------------I'm the split line ^_^----------------------------------------------------- --------



This problem is also wa a lot of times, I was after the problem after the reaction came, very no words of a question, to first accept all the input equals equal treatment
Off, I used to input one side to deal with the equals sign, tle until the early morning to find = =, mainly to first use and check the same elements are all merged
Then as a number processing, and then a topological sort.

#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>UsingNamespace Std;#define INT __int64#define INF0x3f3f3f3fConstint MAXN=22222;int team[MAXN];int Head[MAXN];int point[MAXN];int NXT[MAXN];int edgecnt;int Ingrade[MAXN];int n+ J;Int Road[MAXN];int sum;int A[MAXN], B[MAXN];Char op[MAXN];voidIni(){Memset(Head,-1,sizeof(Head));Memset(Ingrade,0,sizeof(Ingrade)); Edgecnt=0; Sum= N;For(int I=0; I< n; I++){Road[I]= I;}}voidAdd_edge(int U,Int V){NXT[edgecnt]= Head[u]; Point[edgecnt]= V; Head[u]= edgecnt++;}IntFindRoot(int RT){Return Road[RT]= = RT? Rt:(Road[RT]=FindRoot(Road[RT]));}IntMain(){Freopen ("Input.txt", "R", stdin);While(scanf("%d%d\ n",&n,&m)! = EOF){Ini();For(int I=0; I< m; I++){scanf("%d%c%d",&a[I],&op[I],&b[I]);If(OP[I]===){int ROOT1=FindRoot(A[I]);int Root2=FindRoot(B[I]);If(ROOT1! = Root2){Road[Root2]= Root1; Sum--;//remember to subtract one after merging, this is the current number of sets}}}For(int I=0; I< m; I++){If(OP[I]===){Continue;}int a= A[I];int b= B[I]; A=FindRoot(A); B=FindRoot(b);If(OP[I]==' > '){Add_edge(AB); Ingrade[b]++;}Else{Add_edge(bA); Ingrade[A]++;}} queue<Int>q;While(!q.Empty()) Q.Pop();For(int I=0; I< n; I++){If(Ingrade[I]==0&&FindRoot(I)= = I) Q.Push(I)///Note that at this point the root node of road[i] may not be updated, so the query is updated}BOOL Flag=False;While(!q.Empty()){If(q.Size()>1) flag=TrueIf there is more than one point with zero penetration, there must be a number of solutions, the answer is unknown.int now= Q.Front(); Q.Pop(); Sum--;//here to deal with IS to judge the following and there is still wood on the left, if there is, it must be a ring!For(int I= Head[Now]; I!=-1; I= NXT[I]){Int V= Point[I]; Ingrade[V]--;If(!ingrade[V]) Q.Push(V);}}If(Sum>0){Printf("CONFLICT\ n" else if  ( Flag {printf  ( "Uncertain\n  ");  else { Printf ( "Ok\n  ");  } return 0               /span>              

Topological sequencing-and check set-Rank of Tetris

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.