HDU 1811 rank of Tetris (and search set + topology sort)

Source: Internet
Author: User
Tags define local in degrees

Rank of Tetris

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5415 Accepted Submission (s): 1514


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 > < > All-in-one > 1 > + > (>) > (<)

Sample Outputokconflictuncertain

Authorlinle

Sourcehdoj Summer Exercise (2) Idea: Combine points that have the same rank into one point.          Then construct a topology diagram. Then judge the topology map ... (Super Classic One question) code:
1 //#define LOCAL2#include <cstdio>3#include <cstring>4#include <vector>5#include <iterator>6#include <queue>7#include <functional>8 using namespacestd;9 Ten Const intmaxn=20005; One Const intnn=10005; A  - structpath{ -  the    intfr,to; -    Charss[2]; - }TT[MAXN]; -  +vector<int>aa[nn];//Analog adjacency Table - intN,m,num; + intFather[nn]; A intINDE[NN];//in degrees at  - voidinit () { -    for(intI=0; i<n;i++) -father[i]=i; - } -  in intFinintx) { -      while(x!=Father[x]) tox=Father[x]; +   returnx; - } the  * voidUnin (intAintb) { $father[b]=A;Panax Notoginseng } -  the intMain () + { A #ifdef LOCAL theFreopen ("test.in","R", stdin); +      #endif -  $     while(SCANF ("%d%d", &n,&m)! =EOF) { $ init (); -num=N; -        for(intI=0; i<m;i++){ thescanf"%d%s%d",&tt[i].fr,tt[i].ss,&tt[i].to); -        if(tt[i].ss[0]=='='){Wuyi             intx=fin (tt[i].fr); the             inty=fin (tt[i].to); -             if(x!=y) { Wu unin (x, y); -num--; About          } $        } -     } -  -     BOOLErr=0, fight=0; Amemset (Inde,0,sizeof(int) * (n+1)); +  the          for(intI=0; i<n;i++) - aa[i].clear (); $  the          for(intI=0; i<m;i++) the         { the             if(tt[i].ss[0]!='=') the             { -             intx=fin (tt[i].fr); in             inty=fin (tt[i].to); the             if(x==y) { theErr=1;//have contradictions About                  Break; the             } the              //Building a topology diagram the            if(tt[i].ss[0]=='>'){ + aa[x].push_back (y); -inde[y]++; the            }Bayi            Else{ the aa[y].push_back (x); theinde[x]++;//record entry and read the situation -            } -          } the        } the  the         if(err) { theprintf"conflict\n"); -             Continue; the         } the  thequeue<int>Tuop;94         //find all points with an entry level of 0.  the         for(intI=0; i<n;i++) the            if(inde[i]==0&&i==fin (i)) the Tuop.push (i);98  About         while(!Tuop.empty ()) { -            if(Tuop.size () >1){101fight=1;102          }103 104              intgt=Tuop.front (); the Tuop.pop ();106num--;107vector<int>:: iterator ww;108         for(Ww=aa[gt].begin (); Ww!=aa[gt].end (); ww++){109inde[*ww]--; the                if(inde[*ww]==0)111Tuop.push (*ww); the        }113        } the       if(num>0){//Looping theprintf"conflict\n"); the           Continue;117       }118       if(!fight) printf ("ok\n");119       Elseprintf"uncertain\n"); -    }121    return 0;122}
View Code

HDU 1811 rank of Tetris (and search set + topology sort)

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.