HDU3094

/*
树的删边游戏,sg游戏的一种。sg值的计算是这样的。。
定理: 叶子节点的sg为0,中间节点的sg值等于所有子节点的sg加1后的异或
*/

#include <cstdio>
#include <vector>
using namespace std;

int N;
vector<int> G[100001];
int sg[100001];
bool used[100001];

int dfs(int x)
{
	int& cur = sg[x];
	if(cur!=-1) return cur;

	cur = 0;
	used[x] = true;
	for(int i=G[x].size()-1;i>=0;i--)
	{
		if( !used[G[x][i]] )
			cur ^= (dfs( G[x][i] ) + 1);
	}
	used[x] = false;

	return cur;
}

int main()
{
	int T;
	int s,t;
	scanf("%d",&T);
	while(T--)
	{
		while(scanf("%d",&N)==1)
		{
			for(int i=1;i<=N;i++) G[i].clear();
			for(int i=1;i<N;i++)
			{
				scanf("%d %d",&s,&t);
				G[s].push_back(t);
				G[t].push_back(s);
			}

			//
			memset(sg,-1,sizeof(sg));
			if( dfs(1) )
			{
				printf("Alice\n");
			}
			else printf("Bob\n");
		}
	}
	return 0;
}
posted @ 2011-06-15 11:04  AC2012  阅读(203)  评论(0编辑  收藏  举报