您的位置:首页 > 其它

Hdu 6105 Gameia【思维+二分匹配】

2017-08-11 18:19 489 查看


Gameia

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 935    Accepted Submission(s): 403


Problem Description

Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes like this :

0. There is a tree with all node unpainted initial.

1. Because Bob is the VIP player, so Bob has K chances to make a small change on the tree any time during the game if he wants, whether before or after Alice's action. These chances can be used together or separate, changes will happen in a flash. each change
is defined as cut an edge on the tree. 

2. Then the game starts, Alice and Bob take turns to paint an unpainted node, Alice go first, and then Bob.

3. In Alice's move, she can paint an unpainted node into white color.

4. In Bob's move, he can paint an unpainted node into black color, and what's more, all the other nodes which connects with the node directly will be painted or repainted into black color too, even if they are white color before.

5. When anybody can't make a move, the game stop, with all nodes painted of course. If they can find a node with white color, Alice win the game, otherwise Bob.

Given the tree initial, who will win the game if both players play optimally?

 

Input

The first line of the input gives the number of test cases T; T test cases follow.

Each case begins with one line with two integers N and K : the size of the tree and the max small changes that Bob can make.

The next line gives the information of the tree, nodes are marked from 1 to N, node 1 is the root, so the line contains N-1 numbers, the i-th of them give the farther node of the node i+1.

Limits
T≤100
1≤N≤500
0≤K≤500
1≤Pi≤i

 

Output

For each test case output one line denotes the answer.

If Alice can win, output "Alice" , otherwise "Bob".

 

Sample Input

2
2 1
1
3 1
1 2

 

Sample Output

Bob
Alice

题目大意:

A和B两个人玩游戏,A先手,B后手,A每一次操作可以选择任意一个没有染色的点,将其染色为白色。B每一次操作可以选择任意一个没有染色的点,将其染成黑色,并且这个点直接相连的所有点都变成黑色(即使是白色也会被染成黑色)。因为B玩家是VIP玩家,所以他有K次机会拆边,当没有人可以进行操作的时候,游戏结束,当还存在白色点的时候,A赢,否则B赢。

思路:

因为B想赢涉及到拆边之类的复杂操作,所以我们不妨先考虑Bob赢都有哪些情况。

我们通过枚举和YY,不难想到,只有当我们n为偶数,并且能够将图拆成两两配对的情况才能获胜。这样可以有一个对称博弈的思路,就是A先手无论涂哪一个点的颜色,我们Bob都可以后手将这个白色覆盖掉。

那么问题就变成了一个二分图匹配,只有当n%2==0&&K>=(n-1-n/2)的时候,我们的图还是一个能够凑成完美匹配的一个图,才能使得Bob获胜。将边拆剩n/2条,然后两两配对出来。

否则就是Alice赢。

Ac代码:

#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
vector<int>mp[505];
int match[505];
int vis[505];
int f[505];
int find(int u)
{
for(int i=0;i<mp[u].size();i++)
{
int v=mp[u][i];
if(vis[v]==0)
{
vis[v]=1;
if(match[v]==-1||find(match[v]))
{
match[v]=u;
return 1;
}
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)mp[i].clear();
for(int i=2;i<=n;i++)
{
scanf("%d",&f[i]);
mp[f[i]].push_back(i);
mp[i].push_back(f[i]);
}
if(n%2==0&&(n-1-n/2)<=k)
{
int tot=0;
memset(match,-1,sizeof(match));
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))tot++;
}
if(tot==n)printf("Bob\n");
else printf("Alice\n");
}
else printf("Alice\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Hdu 6105