Bnuoj 5966 rank of RIS

Source: Internet
Author: User
Rank of tetristime limit: 1000 msmemory limit: 32768 kbthis problem will be judged on HDU. Original ID: 1811
64-bit integer Io format: % i64d Java class name: Main Since Lele developed the rating system, his Tetris career has become even more powerful, and soon he pushed the game to the world.

To better suit those fans' preferences, Lele came up with a new idea: he will create a global ranking of Tetris experts, which will be updated on a regular basis and the name hall will be better than the Forbes ranking. We don't know how to rank based on rating from high to low. If two people share the same rating, then sort by the RP of these people from high to low.

Finally, Lele is about to take action and rank n people. For convenience, everyone has been numbered, from 0 to N-1, and the larger the number, the higher the RP.
At the same time, Lele obtained some (m) rating information from the paparazzi. There are three possible conditions for such information: "A> B", "A = B", and "A <B", respectively, indicating that the rating of A is higher than B and equal to B, smaller than B.

Now, Lele doesn't ask you to help him create the master list. He just wants to know whether the master list can be determined based on the information. If yes, "OK" is output ". Otherwise, determine the cause of the error, whether it is because the information is incomplete (output "uncertain") or because the information contains conflicts (output "Conflict ").
Note: If the information contains conflicts and the information is incomplete, "Conflict" is output ".
Input this question contains multiple groups of tests, please process until the end of the file.
The first line of each test contains two integers, N, and M (0 <= n <= strong, 0 <= m <= 20000), indicating the number of people to be ranked and the number of relationships obtained.
Next there are m rows, indicating the relationships respectively
Output for each group of tests, the sample input is output in one row according to the requirements of the question
3 30 > 11 < 20 > 24 41 = 21 > 32 > 00 > 13 31 > 01 > 22 < 1
Sample output
OKCONFLICTUNCERTAIN
Sourcehdoj 2007 Summer exercise (2) Problem Solving: query the set...
 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib>10 #include <string>11 #include <set>12 #include <stack>13 #define LL long long14 #define pii pair<int,int>15 #define INF 0x3f3f3f3f16 using namespace std;17 const int maxn = 20010;18 int A[maxn],B[maxn],uf[maxn],n,m;19 char op[maxn][5];20 vector<int>next[10010];21 int pre[10010],sum;22 int Find(int x){23     if(x != uf[x]) uf[x] = Find(uf[x]);24     return uf[x];25 }26 void top_sort(){27     bool uncertain = false;28     queue<int>q;29     for(int i = 0; i < n; i++){30         if(!pre[i] && Find(i) == i) q.push(i);31     }32     while(!q.empty()){33         if(q.size() > 1) uncertain = true;34         int now = q.front();35         q.pop();36         sum--;37         for(int i = 0; i < next[now].size(); i++){38             if(--pre[next[now][i]] == 0) q.push(next[now][i]);39         }40     }41     if(sum > 0) puts("CONFLICT");42     else if(uncertain) puts("UNCERTAIN");43     else puts("OK");44 }45 int main() {46     int i,j;47     while(~scanf("%d %d", &n,&m)){48         for(i = 0; i <= n; i++){49             uf[i] = i;50             next[i].clear();51             pre[i] = 0;52         }53         sum = n;54         for(i = 0; i < m; i++){55             scanf("%d %s %d",A+i,op[i],B+i);56             int tx = Find(A[i]);57             int ty = Find(B[i]);58             if(op[i][0] == ‘=‘){59                 if(tx != ty) {uf[tx] = ty;sum--;}60             }61         }62         for(i = 0; i < m; i++){63             if(op[i][0] == ‘=‘) continue;64             int tx = Find(A[i]);65             int ty = Find(B[i]);66             if(op[i][0] == ‘>‘){67                 pre[ty]++;68                 next[tx].push_back(ty);69             }else if(op[i][0] == ‘<‘){70                 pre[tx]++;71                 next[ty].push_back(tx);72             }73         }74         top_sort();75     }76     return 0;77 }
View code

 

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.