2017 Multi-University Training Contest

来源:互联网 发布:ettercap for windows 编辑:程序博客网 时间:2024/06/08 11:22

Gameia

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


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
 

题目大意:两个人在对一棵树进行博弈,Bob能够在每次操作前一次或者多次将边切断,然后Alice先手点一个未染色的点,然后这个点和所连接的点全部为白色,Bob后手点黑色,两个人都必须点未染色的点,已经被染色的点可以重复被点,现在给Bob m次操作,问获胜的是谁
解题思路:值得注意的事,若是在允许操作的次数之内,可以将所有的点都两两分组,若是可以则Bob可以,否则Alice获胜,至于这个需要用dfs
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;typedef long long LL;vector<int> tu[505];int T,n,m,flag;int vis[505];void dfs(int x,int y){int i,k;for(i=0;i<tu[x].size();i++){k=tu[x][i];if(k==y) continue;dfs(k,x);if(vis[k]==0&&vis[x]==0){vis[k]=1;vis[x]=1;}else{m--;}}}int main(){int k,i,x;cin>>T;while(T--){memset(tu,0,sizeof(tu));cin>>n>>m;for(i=2;i<=n;i++){cin>>x;tu[x].push_back(i);tu[i].push_back(x);}flag=0;memset(vis,0,sizeof(vis));dfs(1,0);for(i=1;i<=n;i++){if(vis[i]==0){flag=1;break;}}if(m<0)flag=1;if(flag){cout<<"Alice"<<endl;}else{cout<<"Bob"<<endl;}}return 0;}


原创粉丝点击