HDU 3094 树上删边 NIM变形
基本的树上删边游戏
写过很多遍了
/** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h> #define LL long long #define PII pair #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5+20; const double eps = 1e-8; vectoredg[N]; int dfs(int x, int pre) { int res = 0; for(auto i : edg[x]) { if(i == pre) continue; res ^= 1 + dfs(i, x); } return res; } int main() { int T; cin >> T; while(T--) { int n; scanf("%d", &n); for(int i = 0; i <= n; i++) edg[i].clear(); for(int i = 0; i < n - 1; i++) { int x, y; scanf("%d%d", &x, &y); edg[x].PB(y); edg[y].PB(x); } int ans = dfs(1, -1); printf("%s\n", ans?"Alice":"Bob"); } return 0; }