HDU6105-Gameia

来源:互联网 发布:网络扫描仪工具 编辑:程序博客网 时间:2024/05/16 05:40

Gameia

                                                                      Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
                                                                                              Total Submission(s): 1370    Accepted Submission(s): 596


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
T100
1N500
0K500
1Pii
 

Output
For each test case output one line denotes the answer.
If Alice can win, output "Alice" , otherwise "Bob".
 

Sample Input
22 113 11 2
 

Sample Output
BobAlice
 

Source
2017 Multi-University Training Contest - Team 6
 

Recommend
liuyiding
 

题意:Alice和Bob玩一个游戏,开始有一颗没有颜色的树,Bob和Alice分别对树进行染色,Alice每次将一个没有颜色的点涂成白色,Bob每次将一个没有颜色的点涂成黑色,并且可以将与涂上黑色的点直接相邻的点变为黑色。Alice为先手,假如最后树上存在白色点,Alice赢,否则Bob赢。Bob可以在任意时候,删除任意一条边。

解题思路:当树为奇数点数时,Alice必赢,偶数的时候,假如Bob能将树划分为所有都是只有两个点相连的话Bob赢



#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <set>#include <string>#include <cmath>#include <algorithm>#include <vector>#include <bitset>#include <stack>#include <queue>#include <unordered_map>#include <functional>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int fa[505],vis[505],c[505],n,k;int s[505],nt[1005],e[1005],flag;void dfs(int k,int f){    for(int i=s[k];~i;i=nt[i])    {        if(e[i]==f) continue;        dfs(e[i],k);        vis[e[i]]--;        if(!flag) return ;    }    if(vis[k]==1&&!c[k]&&!c[f]) c[k]=c[f]=1;    else if(vis[k]==1&&!c[k]&&c[f]) {flag=0;return ;}}int main(){    int t;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&k);        int cnt=0;        memset(s,-1,sizeof s);        memset(vis,0,sizeof vis);        memset(c,0,sizeof c);        for(int i=2;i<=n;i++)        {            scanf("%d",&fa[i]);            nt[cnt]=s[i],s[i]=cnt,e[cnt++]=fa[i];            nt[cnt]=s[fa[i]],s[fa[i]]=cnt,e[cnt++]=i;            vis[i]++,vis[fa[i]]++;        }        if(n%2) {printf("Alice\n");continue;}        flag=1;        dfs(1,0);        if(flag&&k>=(n-1)/2) printf("Bob\n");        else printf("Alice\n");    }    return 0;}