[关闭]
@Chilling 2017-08-12T12:39:49.000000Z 字数 2317 阅读 783

HDU-6105: Gameia (博弈)


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



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

题意: 两个人将一棵树染色,最初树上没有颜色,Alice每一次操作可以将树上的某个没有颜色的节点涂成白色,Bob的每一次操作可以将树上某个没颜色的节点涂成黑色,并且与这个节点直接连接的其他节点(不管有没有涂色),都会被染成黑色。Bob有k把剪刀,可以将树的边剪断(那么就不会被黑色晕染到了,但还是可以被直接涂色),如果最后所有节点都有颜色了,那么游戏结束。如果树上存在白色的点,那么Alice获胜,否则Bob获胜。输入是n和k,表示节点个数和剪刀数量,接下来输入n-1个数字,表示下标(从1开始)的节点与哪个节点相连。

分析:通过在纸上画点找规律,我们可以发现,一条链上且不考虑剪刀的时候,有且只有两个节点的时候,Bob才会赢,否则其他情况都是Alice赢,那么可以猜想,当树的size为2的时候,我们就将上面的边剪掉,从下到上,保证Bob局部获胜,如果最后树的size仍然大于2,或者size为1,那么Alice获胜。


  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 505;
  4. vector<int>V[maxn];
  5. int sz[maxn];
  6. int n, k;
  7. void dfs(int f, int u)
  8. {
  9. sz[u] = 1;
  10. for (int i = 0; i < V[u].size(); i++)
  11. {
  12. int v = V[u][i];
  13. if (v == f) continue;
  14. dfs(u, v);
  15. sz[u] += sz[v];
  16. }
  17. if (k > 0 && sz[u] == 2)
  18. {
  19. k--;
  20. sz[u] = 0;
  21. }
  22. }
  23. void clr()
  24. {
  25. for (int i = 0; i <= n; i++)
  26. V[i].clear();
  27. }
  28. int main()
  29. {
  30. int t;
  31. scanf("%d", &t);
  32. while (t--)
  33. {
  34. scanf("%d %d", &n, &k);
  35. clr();
  36. for (int i = 1; i < n; i++)
  37. {
  38. int x;
  39. scanf("%d", &x);
  40. V[i + 1].push_back(x);
  41. V[x].push_back(i + 1);
  42. }
  43. dfs(0, 1);
  44. if (sz[1] > 2 || sz[1] == 1) printf("Alice\n");
  45. else printf("Bob\n");
  46. }
  47. return 0;
  48. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注