Gameia
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1092 Accepted Submission(s): 461
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
Source
——————————————————————————————
题意:给出一棵树,Alice 和 Bob 轮流操作, Alice先手, Alice的操作是选一个未染色的点将其染成白色,Bob的操作是选一个未染色的点将其染成黑色,并且和这个点有直连边的点也被强制染成黑色(无论这些直连点之前是否有颜色),Bob还有一个小技能是去掉一条边,最后当所有点都有颜色的时候,如果有白色点则Alice赢,否则Bob赢。
思路:首先如果是奇数个点肯定Alice赢,否则Bob肯定得把整棵树两两配对割出来,如果可以则Bob赢否则Alice赢
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
using namespace std;
#define LL long long
#define mem(a,b) memset(a,b,sizeof a);
const int inf=0x3f3f3f3f;
const LL llinf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const LL mod=1e9+7;
const int maxn=2010;
struct node
{
int u,v,next;
} tree[1003];
int fa[1005],s[1005],vis[1005],cnt;
bool isl[1005];
void init()
{
cnt=0;
memset(isl,true,sizeof isl);
memset(s,-1,sizeof s);
}
void add(int u,int v)
{
tree[cnt].u=u;
tree[cnt].v=v;
tree[cnt].next=s[u];
s[u]=cnt++;
}
bool dfs(int x)
{
for(int i=s[x]; ~i; i=tree[i].next)
{
if(isl[tree[i].v]==true&&vis[x]==1)
return 0;
if(isl[tree[i].v])
vis[tree[i].v]=1,vis[x]=1;
else if(!dfs(tree[i].v))
return 0;
}
isl[x]=true;
return 1;
}
3
int main()
{
int T,n,k;
for(scanf("%d",&T); T--;)
{
init();
scanf("%d%d",&n,&k);
for(int i=2; i<=n; i++)
{
scanf("%d",&fa[i]);
isl[fa[i]]=false;
add(fa[i],i);
}
if(n%2)
printf("Alice\n");
else
{
memset(vis,0,sizeof vis);
if(dfs(1)&&k>=(n-1)/2)
{
printf("Bob\n");
}
else
printf("Alice\n");
}
}
return 0;
}