HDU 2412 Party at Hali-Bula

来源:互联网 发布:js获取class元素 编辑:程序博客网 时间:2024/05/21 10:22
#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;}