Reprint Please specify source:http://blog.csdn.net/vmurder/article/details/42653129
In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...
Test instructions: To a tree, each time you can delete a link with node 1 (root) connected edge, the two people take turns operation, who can not operate who loses.
Exercises
Only set formula:
Colon principle: SG (x) =xor{sg (y) +1|y is the child node of x}.
All right. The water.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 101000using namespace Std;struct ksd{int v,next;} E[n<<1];int head[n],cnt;inline void Add (int u,int v) {e[++cnt].v=v;e[cnt].next=head[u];head[u]=cnt;} int n;int sg[n];void DFS (int x,int p) {int i,v;sg[x]=0;for (i=head[x];i;i=e[i].next) {v=e[i].v;if (v==p) Continue;dfs (v,x ); sg[x]^= (sg[v]+1);}} int main () {int I,j,t;int a,b;for (scanf ("%d", &t); t--;) {cnt=1;memset (head,0,sizeof (head)), scanf ("%d", &n), for (i=1;i<n;i++) {scanf ("%d%d", &a,&b); add (A, B), add (B,a);} DFS (1,0), if (Sg[1]) puts ("Alice"), Else puts ("Bob");} return 0;}
"HDU3094" A tree game games, trees-trimmed game