继续水拓扑排序,很简单的一道题,用map映射名字,只要最终结果指向一个人,即冠军,就说明冠军存在
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
int ind[10005];
//int to[10005];
int main()
{
int n;
while(scanf("%d",&n) != EOF && n)
{
memset(ind, 0, sizeof(ind));
map<string, int>m;
int cnt = 0;
for(int i = 1; i <= n; i ++)
{
string s1, s2;
cin>>s1>>s2;
if(!m[s1])m[s1] = ++cnt;
if(!m[s2])m[s2] = ++cnt;
ind[m[s2]] ++;
}
int flag = 0;
// cout<<cnt<<endl;
for(int i = 1; i <= cnt; i ++)
if(! ind[i])
flag += 1;
if(flag == 1)printf("Yes\n");
else printf("No\n");
}
return 0;
}