hdu 5996 dingyeye loves stone
来源:互联网 发布:广发证券炒股软件 编辑:程序博客网 时间:2024/05/16 05:17
dingyeye loves stone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 330 Accepted Submission(s): 186
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]
//hdu 5996#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define ll long long#define M(a) memset(a,0,sizeof a)#define fo(i,j,k) for(i=j;i<=k;i++)using namespace std;const int mxn=100005;int n,T,cnt,ans;int head[mxn],a[mxn],fa[mxn];struct edge {int to,next;} f[mxn];inline void add(int u,int v){ f[++cnt].to=v,f[cnt].next=head[u],head[u]=cnt;}inline void dfs(int u,int dep){ if(dep&1) ans^=a[u]; for(int i=head[u];i;i=f[i].next) { int v=f[i].to; dfs(v,dep+1); }}int main(){ int i,j; scanf("%d",&T); while(T--) { ans=cnt=0; M(head); scanf("%d",&n); fo(i,1,n-1) { scanf("%d",&fa[i]); add(fa[i],i); } fo(i,0,n-1) scanf("%d",&a[i]); dfs(0,0); if(ans==0) printf("lose\n"); else printf("win\n"); } return 0;}
- HDU 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- 【hdu 5996】dingyeye loves stone
- HDU 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- HDU 5996 dingyeye loves stone
- HDU 5996 dingyeye loves stone(Nim 变形)
- HDU 5996 BestCoder Round #90 1002 dingyeye loves stone 博弈
- hdu 5996 dingyeye loves stone nim同阶博弈
- 【HDU 5996 dingyeye loves stone】+ 尼姆博弈
- HDU 5996 dingyeye loves stone (树形博弈)
- HDU 5996 dingyeye loves stone (DFS+博弈)
- hdoj 5996 - dingyeye loves stone(阶段博弈)
- HDOJ 5996 dingyeye loves stone(阶梯博弈)
- dingyeye loves stone
- hdu5996 dingyeye loves stone
- 在Eclipse中安装Hibernate Tools
- Problem B: 平面上的点和线——Point类、Line类 (III)
- POJ 1687 Buggy Sat 笔记
- 最新Retrofit + RxJava + MVP
- java实现serializable接口的作用
- hdu 5996 dingyeye loves stone
- 制作多周期CPU(分析)
- display
- web前端之12种不宜使用的Javascript语法
- Spring框架基本概念,Spring框架模块详解
- LeetCode 376. Wiggle Subsequence
- CodeForces
- Java原码、反码和补码的算法,Java跨平台原理,以及JDK安装目录说明
- DLib中调用人脸对齐+VS2013