There is a tree. Each operation has two steps. The first step is to delete an edge, and the second step is to remove all vertices that are not connected to the root. The final operation won.
Jia Zhihao's Essay: A summary of combined games -- A Discussion on several extensions and variants of SG games
The SG value of the leaf node is 0, and the SG value of the intermediate node is the exclusive or sum after the SG value of all its subnodes plus 1.
For more information, see the thesis.
During the operation, because it is a tree, I still do nothing, add two sides, and then bring them into the parent node in recursion to avoid repetition.
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Define N 10005
# Define LL long
# Define inf 1 <29
# Define eps 1e-7
Using namespace std;
Vector <int> v [100005];
Int get_sg (int u, int pre ){
Int ret = 0;
For (int I = 0; I <v [u]. size (); I ++ ){
If (v [u] [I]! = Pre)
Ret ^ = (1 + get_sg (v [u] [I], u ));
}
Return ret;
}
Int main (){
Int t, n;
Scanf ("% d", & t );
While (t --){
Scanf ("% d", & n );
For (int I = 1; I <= n; I ++)
V [I]. clear ();
For (int I = 1; I <n; I ++ ){
Int x, y;
Scanf ("% d", & x, & y );
V [x]. push_back (y );
V [y]. push_back (x );
}
If (get_sg (1,-1 ))
Puts ("Alice ");
Else
Puts ("Bob ");
}
Return 0;
}
By ACM_cxlove