给你一些点,找出其中点的入度为0的个数,若个数为1,则会产生一个冠军,否则不会。
#include <iostream>
#include <map>
#include <cstdio>
#include <string>
#include <queue>
#include <cstring>
#include <set>
using namespace std;
map<string, int> tmp;
set<string> ans;
void file()
{
freopen("D:\\in.txt", "r", stdin);
// freopen("D:\\out.txt", "w", stdout);
}
int main()
{
// file();
int n;
while (scanf("%d", &n))
{
if (n == 0)
break;
int cnt = 0;
tmp.clear();
ans.clear();
string from, to;
for (int i = 0; i < n; ++i)
{
cin >> from >> to;
ans.insert(from);
ans.insert(to);
tmp[to]++;
}
//cout << cnt << endl;
for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it)
{
if (tmp[*it] == 0)
cnt++;
// cout << *it << endl;
}
// cout << cnt << endl;
if (cnt == 1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}