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?

InputThe 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≤iOutputFor 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
这是一道博弈加上图论的题目,其中博弈的思想比较有意思。
先给出官方题解:

首先解释一下题意,题目说的是,树上不能有白点,否则Alice赢,即使这白点是被切开了,依旧是Alice赢。我只说关键的题意。
接着就是特权的作用:切断之后,防止黑色染到相邻节点,避免节点被染之后自己无处落脚。 题解看不懂的来这里,首先如果树的大小为3的话,alice必赢,因为可以染中间的点,然后无论bob是否能切断,alice都可以染白另一点。
如果是奇数大小的话,Alice必赢,因为Alice可以每次染父节点,将数的大小减二,长此以往,树的大小必然为3,这样Alice必赢。
如果bob能把树分成两个一组的点对,这样bob必赢,这句话里面隐藏了三条信息,首先数是偶数大小,第二bob拥有足够的特权数,即能大于等于n/2-1;
还有就是某一的节点的叶子节点数,如果是奇数个叶子节点的话,bob是无法通过足够的特权将数分成两个一对的点对。
你可以画一个杠铃,然后每个杠铃上再连接两个分开的点,这样就有两个三角型的形状连接在一起了,无论bob有多少特权,这图Alice必赢。虽然图的大小为偶数
且bob特权数足够,但是这有奇数个叶子节点,带上它的父节点,bob跟不上alice的节奏,他必输。这也就是递归所有子节点,求它的数目的原因。
这题大致就是这个思路了,没想明白的可以再仔细想想。既然做了ACM,那就放飞思想吧!

Gameia的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 6 1010 HDU 6105 Gameia (博弈)

    题目链接 Problem Description Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes ...

  2. HDU 6105 - Gameia | 2017 Multi-University Training Contest 6

    /* HDU 6105 - Gameia [ 非平等博弈 ] | 2017 Multi-University Training Contest 6 题意: Bob 可以把一个点和周围所有点都染黑,还有 ...

  3. 2017多校第6场 HDU 6105 Gameia 博弈

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6105 题意:Alice和Bob玩一个游戏,喷漆!现在有一棵树上边的节点最开始都没有被染色.游戏规则是: ...

随机推荐

  1. Android6.0 危险权限和普通权限

    Normal Permissions如下 ACCESS_LOCATION_EXTRA_COMMANDS ACCESS_NETWORK_STATE ACCESS_NOTIFICATION_POLICY ...

  2. TP5之自定义分页样式

    分页样式为 在extend\目录下创建page目录,在page目录下创建Page.php文件,将以下代码放入文件中. <?php namespace page; use think\Pagina ...

  3. java 发送get,post请求

    package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...

  4. asp.net实现服务器文件下载到本地

    1.说明 通过文件下载框实现将服务器上的文件下载到本地指定位置.这里需要指定服务器文件路径 try { string strFilePath = Server.MapPath("~" ...

  5. 7天学完Java基础之3/7

    API概述 什么叫做API? API(Application Programming lnterface),应用程序编程接口. 所谓API就是值好多的类,好多的方法,JDK给我们提供了很多现成的类,我 ...

  6. 树链剖分学习笔记 By cellur925

    先%一发机房各路祖传树剖大师%%%. 近来总有人向我安利树剖求LCA,然鹅我还是最爱树上倍增.然鹅又发现近年一些题目(如天天爱跑步.运输计划等在树上进行操作的题目),我有把树转化为一条链求解的思路,但 ...

  7. 知乎模拟登录 requests session

    Python 3.5 # -*- coding: utf-8 -*- """ Created on Wed May 3 16:26:55 2017 @author: x- ...

  8. AtCoder Grand Contest 018 D - Tree and Hamilton Path

    题目传送门:https://agc018.contest.atcoder.jp/tasks/agc018_d 题目大意: 给定一棵\(N\)个点的带权树,求最长哈密顿路径(不重不漏经过每个点一次,两点 ...

  9. 从一个n位数中选出m位按顺序组成新数并使其最大 || Erasing and Winning UVA - 11491

    就是从n位数中取出n-d个数字按顺序排成一排组成一个新数使得其最大 算法: 从前往后确定每一位.找第i位时,要求后面留下d-i位的空间, 因此第i位应该从第i-1位原来位置+1到第d+i位寻找 用线段 ...

  10. 关于html/css的路径问题

    非原创,转自:http://blog.sina.com.cn/s/blog_6c21f6480101cb33.html [问题描述]: 比如你有Web项目solo,假如目录结构如下: 在cy.css中 ...