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?
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
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
22 113 11 2
Sample Output
BobAlice
Source
2017 Multi-University Training Contest - Team 6
Recommend
liuyiding
#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;}
阅读全文
0 0
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 关于ubuntu下touchegg无效情况。
- Color Me Less
- kernel display模块总结
- IDEA 中构建注册和服务发现中心(一)
- 获取年、月、日、时、分、秒
- 2017 Multi-University Training Contest
- Android弹簧动画 Rebound实战
- (2017多校训练第四场)HDU
- 值栈内部结构
- linux下ffmpeg安装
- 步进电机的技术参数 控制及其应用
- Python3之super关键字
- 初步认识jenkins
- jQuery选择器