Gameia
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 263 Accepted Submission(s): 88
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?
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
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".
If Alice can win, output "Alice" , otherwise "Bob".
Sample Input
2 2 1 1 3 1 1 2
Sample Output
Bob Alice
题解:http://bestcoder.hdu.edu.cn/blog/
a[u]=0,表示这个点已经合法,a[u]=1,表示这个点的子节点合法 当前点还在分割 ,a[u]=2表示当前点不合法;
主要就是节点的状态需要考虑清楚
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include <bits/stdc++.h>
using namespace std;
const int N =100000+10;
vector<int>p[N];
int a[N];
void dfs(int u,int fa)
{
int cnt=0;
if(p[u].size()==0)
{
a[u]=1;
return ;
}
for(int i=0;i<p[u].size();i++)
{
int v=p[u][i];
dfs(v,u);
if(a[v]==1) cnt++;
if(a[v]==2) {a[u]=2; return ;}
}
if(cnt>1) a[u]=2;
else if(cnt==1) a[u]=0;
else if(cnt==0) a[u]=1;
return ;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, k;
scanf("%d %d", &n, &k);
for(int i=0;i<=n;i++) p[i].clear();
for(int i=2;i<=n;i++)
{
int x;
scanf("%d", &x);
p[x].push_back(i);
}
a[1]=2;
dfs(1,-1);
if(a[1]==0&&(n-2)/2<=k) puts("Bob");
else puts("Alice");
}
return 0;
}