UVA#1220Party at Hali-Bula

描述:
类似于最大独立集,略。

#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
const int MAX = 210;
int n,num,d[MAX][2],f[MAX][2];
vector<int> sub[MAX];
map<string,int> dict;//精髓就是建树的过程
int code(const string& s){//const + 引用 提高效率 
	if(!dict.count(s))
		dict[s] = num++;
	return dict[s];
}
int dp(int p,int k){
	int i;
	if(sub[p].empty()){
		f[p][k] = 0;
		return d[p][k] = k;
	}
	int l = sub[p].size();
	d[p][k] = k;
	f[p][k] = 0;
	if(k){
		for(i = 0;i < l; ++i){
			d[p][1] += dp(sub[p][i],0);
			if(f[sub[p][i]][0])
				f[p][1] = 1;
		}
	}
	else{
		for(i = 0;i < l; ++i){
			int t = sub[p][i];
			d[p][0] += max(dp(t,0),dp(t,1));
			if(d[t][0] == d[t][1]){
				f[p][0] = 1;
			}
			else if(d[t][0] > d[t][1] && f[t][0]){
				f[p][0] = 1;
			}
			else if(d[t][0] < d[t][1] && f[t][1]){
				f[p][0] = 1;
			}
		}
	}
	return d[p][k];
} 
int main(){
	//freopen("d://poj//input.txt","r",stdin);
	//freopen("d://poj//data.txt","w",stdout);
	int i;
	string s,s2;
	while(cin >> n && n){
		num = 0;
		dict.clear();
		for(i = 0;i <= n; ++i)
			sub[i].clear();
		cin >> s;
		code(s);
		for(i = 1;i < n; ++i){
			cin >> s >> s2;
			sub[code(s2)].push_back(code(s));
		}
		printf("%d ",max(dp(0,0),dp(0,1)));
		int flag = 0;
//		if((d[0][1] > d[0][0] && !f[0][1]) || (d[0][0] > d[0][1] && !f[0][0]))
//			flag = 1;
//		if(flag)
//			printf("Yes\n");
//		else
//			printf("No\n");
		if(d[0][0] == d[0][1])//莫名其妙,浪费我时间,f**kuasshole
			printf("No\n");
		else if(d[0][0] > d[0][1]){
			if(f[0][0])
				printf("No\n");
			else
				printf("Yes\n");
		}
		else{
			if(f[0][1])
				printf("No\n");
			else
				printf("Yes\n");
		}
	}
	return 0;
}

服务器,你给我翻译翻译,什么叫做他妈是他妈的WA
???

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值