HDU 2412 Party at Hali-Bula

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值