Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 208 Accepted Submission(s): 119

Problem Description

dingyeye loves play stone game with you.

dingyeye has an n-point tree.The nodes are numbered from 0 to n−1,while the root is numbered 0.Initially,there are a[i] stones on the i-th node.The game is in turns.When one move,he can choose a node and move some(this number cannot be 0) of the stones on it to its father.One loses the game if he can’t do anything when he moves.

You always move first.You want to know whether you can win the game if you play optimally.

Input

In the first line, there is an integer T indicating the number of test cases.

In each test case,the first line contains one integer n refers to the number of nodes.

The next line contains n−1 integers fa[1]⋯fa[n−1],which describe the father of nodes 1⋯n−1(node 0 is the root).It is guaranteed that 0≤fa[i] < i.

The next line contains n integers a[0]⋯a[n−1],which describe the initial stones on each nodes.It is guaranteed that 0≤a[i]< 134217728.

1≤T≤100,1≤n≤100000.

It is guaranteed that there is at most 7 test cases such that n>100.

Output

For each test case output one line.If you can win the game,print “win”.Ohterwise,print “lose”.

Sample Input

2

2

0

1000 1

4

0 1 0

2 3 3 3

Sample Output

win

lose

【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=5996

【题解】



可以转化为阶梯博弈;

对深度为偶数的节点进行操作;

相当于一个NIM博弈;

把石子扔掉;

(如果对方对深度为奇数的节点操作,那么你总能把对方扔到偶数深度节点上的石头等量地移动到深度为奇数的节点上);

始终保持偶数深度上节点的石头为你的必胜态(你)或必败态(对方);



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 100000+100; LL a[MAXN],dd;
int n,totm;
int fir[MAXN],nex[MAXN*2],en[MAXN*2]; void dfs(int x,int ndep)
{
if (ndep%2==0)
dd^=a[x];
for (int temp = fir[x];temp;temp = nex[temp])
{
int y = en[temp];
dfs(y,ndep+1);
}
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
int T;
rei(T);
while (T--)
{
totm = 0;
rei(n);
rep1(i,0,n-1)
fir[i] = 0;
rep1(i,1,n-1)
{
int fa;
rei(fa);
nex[++totm] = fir[fa];
fir[fa] = totm;
en[totm] = i;
}
rep1(i,0,n-1)
rel(a[i]);
dd = 0;
dfs(0,1);
if (dd!=0)
puts("win");
else
puts("lose");
}
return 0;
}

【hdu 5996】dingyeye loves stone的更多相关文章

  1. HDU 5996:dingyeye loves stone(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=5996 题意:在一棵树上进行博弈,每次只能将当前的结点的石子放到父节点上,最后不能移动的输. 思路:比赛的时候想的 ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. 【hdu 2486】A simple stone game

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  4. 【HDOJ5996】dingyeye loves stone(Nim游戏)

    题意:dingyeye喜欢和你玩石子游戏.dingyeye有一棵n个节点的有根树,节点编号为0到n−1,根为0号节点. 游戏开始时,第i个节点上有a[i]个石子.两位玩家轮流操作,每次操作玩家可以选择 ...

  5. 【HDU 6021】 MG loves string (枚举+容斥原理)

    MG loves string  Accepts: 30  Submissions: 67  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  6. 【HDU 6020】 MG loves apple (乱搞?)

    MG loves apple  Accepts: 20  Submissions: 693  Time Limit: 3000/1500 MS (Java/Others)  Memory Limit: ...

  7. 【2014 Multi-University Training Contest 2 1002】/【HDU 4873】 ZCC Loves Intersection

    果然,或滥用零件,啥都不说了.我们欣慰地学习阅读.这两天残疾儿童是数学. 这是求所需的问题,不明确.贴上官方的解题报告. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi ...

  8. hdu 5996 dingyeye loves stone(博弈)

    题目链接:hdu 5996 dingyeye loves stone 题意: 给你一棵树,树的每一个节点有a[i]个石子,每个人可以将这个节点的石子移向它的父亲,如果没有合法操作,那么就算输,现在给你 ...

  9. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

随机推荐

  1. 怎样 TabHostFragment自己定义 tab键(indicator)

    1 获得 tabHostFragment: ActionBarActivity activity2 = (ActionBarActivity) activity; mTabHost = new Fra ...

  2. shell-查看手机分辨率

    使用如下命令,可以查看手机分辨率 adb shell dumpsys window displays 运行结果如下 Display: mDisplayId= init=1080x1920 480dpi ...

  3. JQuery滑动到指定位置

    $('html, body').animate({ scrollTop: next_tip.offset().top + "px"},500);

  4. 开源企业IM-免费企业即时通讯-ENTBOOST V2014.177 Windows版本号正式公布

    ENTBOOST,VERSION 2014.177 LINUX 版本号公布.主要添加Android安卓手机开发接口.企业IM接口,JQUERY开发接口,PCclient部分BUG修正: 下版本号更新时 ...

  5. shell基础之符号与语法

            shell脚本如今已经成为了一种非常普遍的脚本语言,之所以如此广泛的被应用,毋庸置疑它是有它的独到之处的.shell脚本语言和其它的语言比方说c/c++有何不同呢?c/c++等语言属于 ...

  6. 最新GitHub新手使用教程(Windows Git从安装到使用)——详细图解

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 一.叙述 1.Git简介 Git(读音为/gɪt/.)是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本 ...

  7. 扩展的方法:es6 安装模块builder

    https://github.com/es-shims/es5-shim/ Image.png 检测浏览器可支持es5,不支持就扩展,做兼容: 扩展的方法: Image.png 取所有对象的键值: o ...

  8. SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例

    SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例 这是一个简单的SpringBoot整合实例 这里是项目的结构目录 首先是pom.xml ...

  9. [Android5.1]ActivityManagerService启动过程分析

    ActivityManagerService(简称AMS)是Android系统的关键服务之中的一个.它的主要作用例如以下: 管理系统中全部应用进程的整个生命周期 管理应用进程中的Activity.Se ...

  10. jtag引脚

    如果不能下载,可能原因也许是电量不足了... 在电力不足的时候,仿真也不能进行... ///////////////////////////////////////////////////////// ...