HDU 3904 A tree game)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.