Hangzhou Electric 2094--Generation Champion (topological sort)

Source: Internet
Author: User

Produce Champions

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


Problem description A group of people, playing table tennis game, 22 catch to kill, every two people play a maximum of a game.
The rules of the game are as follows:
If a defeated B,b and defeated C, and A and C did not play, then it is decided that a must be able to defeat C.
If a defeated B,b and defeated C, and C defeated A, then a, B, C Three will not be the champion.
According to this rule, there is no need to cycle a contest, perhaps to determine the championship. Your task is to face a group of contestants, after a number of killings, to determine whether it has actually produced a championship.

Input inputs contain a number of contestants, each of which starts with an integer n (n<1000) followed by N against the competitor, and the result is a pair of player names (one space between them), the former defeating the latter. If n is 0, it indicates the end of the input.

Output for each player group, if you determine that a winner is generated, export "Yes" in one line, otherwise output "No" in a row.

Sample Input3 Alice Bob Smith John Alice Smith5 a cc D d e b ea d 0

Sample Outputyes No

Authorqianneng

Source greets new semester-super easy version

Recommendlcy | We have carefully selected several similar problems for you:2093 1811 2086 2647 2090 RE: It is said that a winner is one who has not lost.
1#include <map>2#include <cstdio>3#include <cstring>4#include <iostream>5 using namespacestd;6map<string,int>acc;7 intvis[1010], pic[1010][1010], indegree[1010];8 BOOLFlag;9 intN, K, top;Ten voidDeal () One { Amemset (Vis,0,sizeof(Vis)); -memset (pic,0,sizeof(pic)); -memset (Indegree,0,sizeof(Indegree)); theAcc.clear ();stringA, B; K =0; -          for(inti =0; I < n; i++) -         { -Cin >> a >>b; +             if(!acc[a]) acc[a] = + +K; -             if(!acc[b]) acc[b] = + +K; +             if(Pic[acc[a]][acc[b]] = =0) A             { atPIC[ACC[A]][ACC[B]] =1; -indegree[acc[b]]++;  -             }     -         } -         intTotal =0;  -          for(inti =1; I <= K; i++) in             if(!Indegree[i]) -total++; to         if(Total! =1) +Flag =false; - } the voidTsort () * { $top =0;inti;Panax Notoginseng      while(Top <k) -     { the          for(i =1; I <= K; i++) +             if(!vis[i] &&!Indegree[i]) A                  Break; theVis[i] =1; +top++; -          for(intj =1; J <= K; J + +) $             if(Pic[i][j]) $indegree[j]--; -     } - }  the  - /*void Tsort () {//wa: There is no guarantee that there is only one person who has not lost. Wuyi int m; the For (int j = 0; J < K; J + +) { - m =-1; Wu for (int i = 1; I <= K; i++) - if (!indegree[i]) { About m = i; $ Break ; -             } - if (m = =-1) { - flag = false; A Break ; +             } the indegree[m]--; - for (int i = 1; I <= K; i++) { $ if (Pic[m][i]) the indegree[i]--; the             } the     } the } */ -  in intMain () the { the      while(~SCANF ("%d", &N), N) About     { theFlag =true; the Deal (); the Tsort (); +         if(Top <k)//seems to be a judgment ring.  -Flag =false; the         if(flag)Bayiprintf"yes\n"); the         Else theprintf"no\n"); -     } -     return 0; the}

Hangzhou Electric 2094--Generation Champion (topological 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.