Rank of Tetris
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9267 Accepted Submission (s): 2668
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 INPUT3 > < > 2 4 = 1 > > > 1 3 > > < +
Sample Outputokconflictuncertain
Title Link: HDU 1811
Test Instructions: given n points and m relationships, you can make a =, >, or < To determine the size relationship of the N-point.
See equals sign = You can use and check the set to deal with the point of equal relations are indented a point, and then is to determine whether the graph after the indentation is a DAG, if not a DAG is conflict, or whether it is uncertain, how to judge it? Using a dis array to sort out the hierarchical relationship of the point distance starting point, if there are two points of the dis is the same, then the relationship between the two points is not clear, or there is a certain contraction point it does not have the edge and the edge, and its rank is less than the total number of N, indicating that the set is isolated, the set of points Of course, you first have to deal with the contraction point offline, or in case the input order changes, the addition of the edge is not right
To two sets of data:
3 1
1 = 0
Uncertain
2 1
1 = 0
Ok
Code:
#include <stdio.h> #include <bits/stdc++.h>using namespace std; #define INF 0x3f3f3f3f#define LC (x) (x< <1) #define RC (x) ((x<<1) +1) #define MID (x, y) ((x+y) >>1) #define CLR (Arr,val) memset (arr,val,sizeof (arr) ) #define FAST_IO Ios::sync_with_stdio (false); Cin.tie (0); typedef pair<int, int> pii;typedef Long Long ll;const Double PI = ACOs ( -1.0); const int N = 10010;const int M = 20010;struct edge{int to, NXT; Edge () {} edge (int _to, int _nxt): to (_to), NXT (_NXT) {}} e[n];struct info{int A, b; Char ops[3];} Rela[m];int Head[n], Tot;int in[n], out[n], pre[n], ran[n], cnt[n], vis[n], dis[n];void init () {CLR (head,-1); tot = 0; CLR (in, 0); CLR (out, 0); CLR (Pre,-1); CLR (CNT, 0); CLR (Vis, 0); CLR (DIS, 0); Fill (ran, ran + N, 1);} int Find (int n) {return pre[n] = =-1? n:pre[n] = Find (Pre[n]);} void Joint (int a, int b) {a = Find (a); b = Find (b); if (a = = b) return; Pre[a] = b; RAN[B] + = Ran[a]; Ran[A] = 0;} inline void Add (int s, int t) {E[tot] = Edge (t, Head[s]); Head[s] = tot++;} int top_sort1 (int n) {queue<int>q; int i; bool uncertain = false, conflict = false; for (i = 0; i < n; ++i) {int fi = Find (i); if (!vis[fi] &&!in[fi]) {Q.push (FI); DIS[FI] = 1; ++CNT[DIS[FI]]; VIS[FI] = 1; } if (!out[fi] &&!in[fi] && Ran[fi] < n) uncertain = true; } CLR (Vis, 0); while (! Q.empty ()) {int u = q.front (); Q.pop (); for (i = head[u]; ~i; i = e[i].nxt) {int v = e[i].to; if (--in[v] = = 0) {Q.push (v); DIS[V] = Dis[u] + 1; if (!vis[v]) ++cnt[dis[v]]; }}} for (i = 0; i < n; ++i) {int fi = Find (i); if (In[fi]) {conflict = true; Break }} for (i = 1; I <= n; ++i) {if (Cnt[i] >= 2) {uncertain = true; Break }} if (conflict) return-1; else if (uncertain) return 0; return 1;} int main (void) {int n, m, I; while (~SCANF ("%d%d", &n, &m)) {init (); for (i = 0; i < m; ++i) {scanf ("%d%s%d", &RELA[I].A, Rela[i].ops, &rela[i].b); if (rela[i].ops[0] = = ' = ') joint (RELA[I].A, rela[i].b); } for (i = 0; i < m; ++i) {if (rela[i].ops[0] = = ' = ') continue; if (rela[i].ops[0] = = ' < ') swap (RELA[I].A, rela[i].b); int fa = Find (rela[i].a), fb = find (rela[i].b); Add (FA, FB); ++IN[FB]; ++OUT[FA]; } int ans = TOP_SORT1 (n); if (ans = = 1) puts ("OK"); else if (ans = = 0) puts ("uncertain"); ElSe puts ("CONFLICT"); } return 0;}
HDU 1811 rank of Tetris (and check set by rank merge + topology sort)