HDU 2094 Generation Champion

Source: Internet
Author: User

Produce Champions




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 input3alice bobsmith Johnalice smith5a CC dd EB ea d0

Sample Outputyesno At first, I thought it was a topological sort, and it was only one point that judged the entry to be 1.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <string>5#include <algorithm>6#include <map>7 using namespacestd;8 9map<string,int>ID;Ten intg[1005][1005]; One BOOLindegree[1005]; A intnum; -  - BOOLToposort () the { -     intcnt,i; -      for(cnt=i=0; i<num;i++) -     { +         if(Indegree[i]) -cnt++; +     } A     if(cnt!=num-1)return false; at     return true; - } -  - intMain () - { -     //freopen ("In.txt", "R", stdin); in     intN; -     strings1,s2; to      while(SCANF ("%d",&N), N) +     { -num=0; the id.clear (); *memset (Indegree,0,sizeof(Indegree)); $memset (G,0,sizeof(G));Panax Notoginseng          for(intI=0; i<n;i++) -         { theCin>>s1>>S2; +             if(!Id.count (S1)) Aid[s1]=num++; the             if(!id.count (S2)) +id[s2]=num++; -                 if(!G[id[s1]][id[s2]]) $indegree[id[s2]]=true; $g[id[s1]][id[s2]]=1; -         } -         BOOLans=Toposort (); the         if(ANS) -printf"yes\n");Wuyi         Else theprintf"no\n"); -     } Wu     return 0; - } About  $  - /*The judging graph has a unique topological sequence - #include <cstdio> - #include <iostream> A #include <cstring> + #include <string> the #include <algorithm> - #include <map> $ using namespace std; the  the map<string,int>id; the int g[1005][1005]; the bool indegree[1005]; - int num; in int c[1005]; the  the bool Dfs (int u) About { the C[u]=-1; the for (int v=0;v<num;v++) the     { + if (G[u][v]) -         { the if (c[v]<0) return false;Bayi Else if (!c[v]&&!dfs (v)) return false; the         } the     } - c[u]=1; - return true; the } the  the bool Toposort () the { - int flag; the int cnt,i; the memset (c,0,sizeof (c)); the For (cnt=i=0;i<num;i++)94     { the if (indegree[i]==false) the flag=i; the Else98 cnt++; About     } - if (cnt!=num-1) return false;101 if (!DFS (flag)) return false;102 return true;103 }104  the int main ()106 {107 //freopen ("In.txt", "R", stdin);108 int n;109 string s1,s2; the while (scanf ("%d", &n), N)111     { the num=0;113 id.clear (); the memset (indegree,0,sizeof (Indegree)); the memset (g,0,sizeof (G)); the for (int i=0;i<n;i++)117         {118 cin>>s1>>s2;119 if (!id.count (S1)) - id[s1]=num++;121 if (!id.count (S2))122 id[s2]=num++;123 if (! G[ID[S1]][ID[S2]])124 indegree[id[s2]]=true; the g[id[s1]][id[s2]]=1;126         }127 bool Ans=toposort (); - if (ans)129 printf ("yes\n"); the Else131 printf ("no\n"); the     }133 return 0;134 }135 */

HDU 2094 Generation Champion

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.