首页 > 其他 > 详细

HDU 3094 A tree game 树删边游戏

时间:2015-08-08 14:55:24      阅读:233      评论:0      收藏:0      [点我收藏+]

叶节点SG值至0 非叶节点SG值至于它的所有子节点SG值添加1 XOR和后

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
vector <int> G[100010];
int sg[100010];
int dfs(int x, int f)
{
	if(sg[x] != -1)
		return sg[x];
	if(!G[x].size())
		return 0;
	int ans = 0;
	for(int i = 0; i < G[x].size(); i++)
	{
		int v = G[x][i];
		if(v == f)
			continue;
	ans ^= dfs(v, x)+1;
	}
	return ans;
}
int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		memset(sg, -1, sizeof(sg));
		int n;
		scanf("%d", &n);
		for(int i = 1; i <= n; i++)
			G[i].clear();
		for(int i = 1; i < n; i++)
		{
			int u, v;
			scanf("%d %d", &u, &v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		int ans = dfs(1, -1);
		if(ans)
			puts("Alice");
		else
			puts("Bob");
	}
	return 0;
}


版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 3094 A tree game 树删边游戏

原文:http://www.cnblogs.com/mengfanrong/p/4713121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!