#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
struct node{
int in,no;
};
struct link{
int nex,to;
}L[509];
int F[509];
map<string,int> mp;
int cnt,cntl,n;
void add(int f,int t)
{
L[cntl].nex = F[f];
L[cntl].to = t;
F[f] = cntl;
cntl++;
}
void init()
{
cnt = cntl = 1;
memset(F,0,sizeof(F));
int f,t;
char name[205];
scanf("%s",name);
mp.clear();
string str;
str = name;
mp[str] = cnt++;
for(int i=1;i<n;i++)
{
scanf("%s",name);
str = name;
if(mp.find(str)==mp.end())
{
mp[str] = cnt++;
}
t = mp[str];
scanf("%s",name);
str = name;
if(mp.find(str)==mp.end())
{
mp[str] = cnt++;
}
f = mp[str];
add(f,t);
}
}
int dup[205][2];
bool mut;
node dfs(int k)
{
int in=1,no=0;
dup[k][0] = dup[k][1] = 1;
for(int i=F[k];i;i=L[i].nex)
{
int to = L[i].to;
node t = dfs(to);
no+=max(t.in,t.no);
in+=t.no;
if(dup[to][0] == 0) dup[k][1] = 0;
if(t.in==t.no) dup[k][0] = 0;
}
node tmp;tmp.in = in,tmp.no = no;
return tmp;
}
void solve()
{
mut = true;
node t = dfs(1);
if((t.no>t.in&&dup[1][0])||(t.in>t.no&&dup[1][1])) mut = false;
printf("%d %s\n",max(t.in,t.no),mut?"No":"Yes");
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%d",&n)&&n)
{
init();
solve();
}
return 0;
}
HDU 2412 Party at Hali-Bula
最新推荐文章于 2022-11-03 22:48:41 发布