hdu 2094 产生冠军

题意:给定n组u关系。每组表示a战胜b。。问根据这些关系能否确定冠军。 思路:如果a战胜b就从a连一条指向b的边。那么能确定冠军的条件就变成了,有且只有一个入度为0的点。翻译过来就是,有一个人没有被任何人战胜过。且,这样的人只有一个。一开始想用map来搞。。但是比较麻烦。。其实用set比较好。。开两个set,一个存所有的人,一个存输过的人。出度为0的点只有一个等价为,有且只有一个人没有输过。也就是两个set的元素差个数为1.

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月08日 星期二 21时11分20秒
 4File Name :code/hdu/2094.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int  N= 1E3+7;
34int n;
35set<string>all;
36set<string>loser;
37int main()
38{
39	#ifndef  ONLINE_JUDGE 
40	freopen("code/in.txt","r",stdin);
41  #endif
42
43	    while (scanf("%d",&n)!=EOF)
44	    {
45		all.clear();
46		loser.clear();
47		if (n==0) break;
48		for ( int i = 0 ; i < n ;i++)
49		{
50		    string win,lose;
51		    cin>>win>>lose;
52		    all.insert(win);
53		    all.insert(lose);
54		    loser.insert(lose);
55		}
56		if (all.size()-loser.size()==1)
57		{
58		    puts("Yes");
59		}
60		else
61		{
62		    puts("No");
63		}
64	    }
65
66  #ifndef ONLINE_JUDGE  
67  fclose(stdin);
68  #endif
69    return 0;
70}