HDU 3094 A tree game 树的删边游戏
来源:互联网 发布:psp go 自制软件 编辑:程序博客网 时间:2024/06/08 01:01
叶子节点的SG值为0 非叶子节点的SG值为为它的所有子节点的SG值加1 后的异或和
#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");elseputs("Bob");}return 0;}
0 0
- HDU 3094 A tree game 树的删边游戏
- HDU 3094 A tree game(树上删边游戏)
- hdu 3094 A tree game (树形删边游戏)
- HDU 3904 A tree game(树的删边游戏,树形图博弈)
- hdu3094 A tree game----树的删边游戏
- hdu 3094 A tree game (博弈 树的删边问题)
- HDU 3094 A tree game
- HDU 3094 A tree game
- 【HDU3094】A tree game 博弈,树形删边游戏
- hdu 3094——A tree game
- HDU 5299 Circles Game(树的删边游戏)
- HDU 3904 A tree game题解
- hdu 3094 A tree game 2009 Multi-University Training Contest 18 - Host by ECNU
- hdu3094 A tree game
- hdu 5299(树上删边游戏) Circles Game
- HDU A simple stone game [K倍动态减法游戏]
- [POJ3710]Christmas Game(博弈树的删边游戏)
- 游戏中AI的行为树(Behaviour Tree in Game AI)
- SharePoint 2013 Silverlight中使用Net客户端对象模型
- [Phonegap+Sencha Touch] 移动开发38 sencha 2.3.2+ 在 安卓2.3上使用报错 - has no method 'bind'
- 第十三周项目一(1) 数组简单试
- 数组大折腾(3)
- Lua脚本之基础语法
- HDU 3094 A tree game 树的删边游戏
- Android 5.0以下使用Material Design 特性
- 第十三周 项目1.1 1.2 1. 3 ——数组的赋值与输出
- 【VBA研究】查找文件夹下面所有文件的名称
- 第十三周项目一数组大折腾(2)
- mysq 时间相差
- 第13周项目1(1)-数组大折腾
- Duilib学习笔记《02》— 界面布局
- 第十三周项目一:数组大折腾(一)