J - Gameia HDU - 6105 树上博弈

版权声明: https://blog.csdn.net/nucleare/article/details/89083566

J - Gameia

 HDU - 6105 

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≤100T≤100 
1≤N≤5001≤N≤500 
0≤K≤5000≤K≤500 
1≤Pi≤i1≤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

https://blog.csdn.net/dreams___/article/details/77103683

https://www.cnblogs.com/From-scratch/p/7348216.html

#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 555;

int degree[N];
int head[N], en;
struct Edge {
	int v, to;
} e[N*2];
void adde(int u, int v) {
	e[++en].v = v;
	e[en].to = head[u];
	head[u] = en;
} 
int dfs(int u) {
	int num = 0;
	for (int i = head[u]; ~i; i = e[i].to) {
		if (degree[e[i].v] == 1) ++num;
	}
	if (num < 2) return 0;
	return 1;
}
int main() {
	int t;
	scanf ("%d", &t);
	while (t--) {
		int n, k;
		scanf ("%d  %d", &n, &k);
		int fa;
		memset(degree, 0, sizeof(degree));
		memset(head, -1, sizeof(head)); en = 0;
		for (int i = 2; i <= n; ++i) {
			scanf ("%d", &fa);
			adde(fa, i), adde(i, fa);
			++degree[fa], ++degree[i];
		}
		if ((n&1) || n/2-1 > k) {
			puts("Alice");
			continue;
		}
		int flag = 0;
		for (int i = 1; i <= n; ++i) if (dfs(i)) {
			flag = 1; break;
		}
		if (flag) puts("Alice");
		else puts("Bob");
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/nucleare/article/details/89083566