1 #include<cstdio>
2 #include<algorithm>
3 #include<cstring>
4 #include<iostream>
5 #include<string>
6 #include<map>
7 using namespace std;
8 map<string,int> nameCache;
9 int nowID,n;
10 string boss;
11 struct Edge
12 {
13 int to,next;
14 }edge[300];
15 int num_edge,first[300];
16 int dp1[300][2];
17 bool dp2[300][2];
18 bool vis[300];
19 //[][1]表示选此点,[][0]表示不选此点,dp1记录最多选的人数,dp2记录是否唯一
20 void dp(int x)
21 {
22 int k=first[x];
23 dp2[x][1]=true;
24 dp1[x][1]=1;
25 dp2[x][0]=true;
26 dp1[x][0]=0;
27 vis[x]=true;
28 while(k!=0)
29 {
30 if(!vis[edge[k].to]) dp(edge[k].to);
31 dp1[x][1]+=dp1[edge[k].to][0];
32 dp2[x][1]&=dp2[edge[k].to][0];
33 if(dp1[edge[k].to][0]>dp1[edge[k].to][1])
34 {
35 dp1[x][0]+=dp1[edge[k].to][0];
36 dp2[x][0]&=dp2[edge[k].to][0];
37 }
38 else if(dp1[edge[k].to][0]<dp1[edge[k].to][1])
39 {
40 dp1[x][0]+=dp1[edge[k].to][1];
41 dp2[x][0]&=dp2[edge[k].to][1];
42 }
43 else
44 {
45 dp1[x][0]+=dp1[edge[k].to][1];
46 dp2[x][0]=false;
47 }
48 k=edge[k].next;
49 }
50 }
51 int main()
52 {
53 int i,t1,t2;
54 string str,str2;
55 cin>>n;
56 while(n!=0)
57 {
58 cin>>boss;
59 nameCache.clear();
60 num_edge=0;
61 nowID=1;
62 nameCache[boss]=0;
63 memset(vis,0,sizeof(vis));
64 memset(first,0,sizeof(first));
65 for(i=1;i<n;i++)
66 {
67 cin>>str>>str2;
68 if(nameCache.count(str)==0)
69 {
70 t1=nowID++;
71 nameCache[str]=t1;
72 }
73 else
74 t1=nameCache[str];
75 if(nameCache.count(str2)==0)
76 {
77 t2=nowID++;
78 nameCache[str2]=t2;
79 }
80 else
81 t2=nameCache[str2];
82 edge[++num_edge].to=t1;
83 edge[num_edge].next=first[t2];
84 first[t2]=num_edge;
85 }
86 dp(0);
87 if(dp1[0][0]>dp1[0][1])
88 {
89 printf("%d ",dp1[0][0]);
90 if(dp2[0][0]==true)
91 printf("Yes\n");
92 else
93 printf("No\n");
94 }
95 else if(dp1[0][0]<dp1[0][1])
96 {
97 printf("%d ",dp1[0][1]);
98 if(dp2[0][1]==true)
99 printf("Yes\n");
100 else
101 printf("No\n");
102 }
103 else
104 printf("%d No\n",dp1[0][1]);
105 cin>>n;
106 }
107 return 0;
108 }