3 Alice Bob Smith John Alice Smith 5 a c c d d e b e a d 0
Yes No
#include<string>
#include<iostream>
#include<set>
#include<map>
using namespace std;
int main()
{
int n;
while(cin>>n,n)
{
set<string>cnt;
map<string , string >dict;
string str1,str2;
for(int i=0; i<n; i++)
{
cin>>str1>>str2;
cnt.insert(str1);
cnt.insert(str2);
dict[str2]=str1;
}
int count=0;
for(set<string>::iterator it=cnt.begin(); it!=cnt.end(); it++)
{
if(dict[*it].empty()==1)//如果只存在一个入度为0的结点,才可判断产生冠军。
count++;
}
if(count==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
原文地址:http://blog.csdn.net/lsgqjh/article/details/45958401