题意:
N<=105的一棵树,双方每次可以选择一条边删去,并且把不与根相连的边一并删去,不能操作者输
分析:
有一个结论sgleaf=0,其他节点sgu=xor∑v(1+sgv)(v为u的儿子)
证明见贾志豪《组合游戏略述——浅谈SG游戏的若干拓展及变形》
代码:
//
// Created by TaoSama on 2015-11-24
// Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n;
vector<int> G[N];
int dfs(int u, int f) {
int ret = 0;
for(int v : G[u]) {
if(v == f) continue;
ret ^= (1 + dfs(v, u));
}
return ret;
}
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
int t; scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) G[i].clear();
for(int i = 1; i < n; ++i) {
int u, v; scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
puts(dfs(1, -1) ? "Alice" : "Bob");
}
return 0;
}