dingyeye loves stone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 48 Accepted Submission(s): 27
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
该开始单纯尼姆博弈~果断WA~之后想到偶数深度的贡献的不用考虑~却没再运用尼姆博弈~偶然间看到CZY学长的分数~1913~先膜~=-=~
AC代码:
#include<cstdio>
#include<vector>
using namespace std;
const int MAXN = 1e5 + 10;
int ma[MAXN],ans;
vector <int> v[MAXN];
void DFS(int x,int y){
if(y & 1) ans ^= ma[x];
for(int i = 0 ; i < v[x].size() ; i++)
DFS(v[x][i],y + 1);
}
int main()
{
int T,N,a;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i = 0 ; i <= N ;i++) v[i].clear();
for(int i = 1 ; i < N; i++){
scanf("%d",&a);
v[a].push_back(i);
}
ans = 0;
for(int i = 0 ; i < N ; i++)
scanf("%d",&ma[i]);
DFS(0,0);
printf(ans ? "win\n" : "lose\n");
}
return 0;
}