HDU 3094 A tree game 树删边游戏
2015-08-08 14:36
274 查看
叶节点SG值至0 非叶节点SG值至于它的所有子节点SG值添加1 XOR和后
#include <cstdio> #include <cstring> #include <vector> using namespace std; vector <int> G[100010]; int sg[100010]; int dfs(int x, int f) { if(sg[x] != -1) return sg[x]; if(!G[x].size()) return 0; int ans = 0; for(int i = 0; i < G[x].size(); i++) { int v = G[x][i]; if(v == f) continue; ans ^= dfs(v, x)+1; } return ans; } int main() { int T; scanf("%d", &T); while(T--) { memset(sg, -1, sizeof(sg)); int n; 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); } int ans = dfs(1, -1); if(ans) puts("Alice"); else puts("Bob"); } return 0; }
相关文章推荐
- 操作系统之页面置换算法
- [leetcode] Two Sum
- POJ 3007 Organize Your Train part II(枚举)
- 当webview遇到360wifi
- PHP模拟asp中response类实现方法
- django 快速搭建blog
- 程序员面试宝典(第四版)——读书笔记-1、第五章:程序设计基本概念
- 网站右侧导航条的玩法
- Codeforces Round #312 (Div. 2)
- NEUQ 1209: 内码对称
- 【NYIST】暑假训练赛 (一)----Problem F
- jsonp不能post!
- 剑指offer面试题46:求1+2+...+n
- 剪切板(复制、粘贴)工具类
- JavaScript面向对象之类的创建
- MATLAB图像处理命令
- String 相关操作
- Android 开发资源
- tableView 解决加载数据混乱问题
- MySQL语法大全_自己整理的学习笔记