hdu 3094 A tree game 树上sg
A tree game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Given is a tree on N vertices, The vertices are numbered from 1 to N. vertex 1 represents the root. There are N-1 edges. Players alternate in making moves, Alice moves first. A move consists of two steps. In the first step the player selects an edge and removes it from the tree. In the second step he/she removes all the edges that are no longer connected to the root. The player who has no edge to remove loses.
You may assume that both Alice and Bob play optimally.
Each test case begins with a line containing an integer N (1<=N<=10^5), the number of vertices,The following N-1 lines each contain two integers I , J, which means I is connected with J. You can assume that there are no loops in the tree.
3
1 2
2 3
3
1 2
1 3
10
6 2
4 3
8 4
9 5
8 6
2 7
5 8
1 9
6 10
Bob
Alice
树上基础博弈:sg[u]={sg[v]+1}异或和 u是v的父亲;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL __int64
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; vector<int>edge[N];
int sg[N];
void dfs(int u,int fa)
{
for(int i=;i<edge[u].size();i++)
{
int v=edge[u][i];
if(v==fa)continue;
dfs(v,u);
sg[u]^=sg[v]+;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(sg,,sizeof(sg));
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
edge[i].clear();
for(int i=;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
edge[u].push_back(v);
edge[v].push_back(u);
}
dfs(,-);
if(sg[])printf("Alice\n");
else printf("Bob\n");
}
return ;
}
hdu 3094 A tree game 树上sg的更多相关文章
- HDU 3094 A tree game
Problem Description Alice and Bob want to play an interesting game on a tree.Given is a tree on N ve ...
- hdu 3094 A tree game 博弈论
思路: 叶子节点的SG值为0:中间节点的SG值为它的所有子节点的SG值加1 后的异或和. 详见贾志豪神牛的论文:组合游戏略述 ——浅谈SG游戏的若干拓展及变形 代码如下: #include<cs ...
- HDU 3094 A tree game 树删边游戏
叶节点SG值至0 非叶节点SG值至于它的所有子节点SG值添加1 XOR和后 #include <cstdio> #include <cstring> #include < ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 4871 Shortest-path tree 最短路 + 树分治
题意: 输入一个带权的无向连通图 定义以顶点\(u\)为根的最短路生成树为: 树上任何点\(v\)到\(u\)的距离都是原图最短的,如果有多条最短路,取字典序最小的那条. 然后询问生成树上恰好包含\( ...
- Hdu 5379 Mahjong tree (dfs + 组合数)
题目链接: Hdu 5379 Mahjong tree 题目描述: 给出一个有n个节点的树,以节点1为根节点.问在满足兄弟节点连续 以及 子树包含节点连续 的条件下,有多少种编号方案给树上的n个点编号 ...
- HDU 5513 Efficient Tree
HDU 5513 Efficient Tree 题意 给一个\(N \times M(N \le 800, M \le 7)\)矩形. 已知每个点\((i-1, j)\)和\((i,j-1)\)连边的 ...
- HDU 4925 Apple Tree(推理)
HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定 ...
- HDU 6035 - Colorful Tree | 2017 Multi-University Training Contest 1
/* HDU 6035 - Colorful Tree [ DFS,分块 ] 题意: n个节点的树,每个节点有一种颜色(1~n),一条路径的权值是这条路上不同的颜色的数量,问所有路径(n*(n-1)/ ...
随机推荐
- Redis内存分析方法
一般会采用 bgsave 生成 dump.rdb 文件,再结合 redis-rdb-tools 和 sqlite 来进行静态分析. BGSAVE:在后台异步(Asynchronously)保存当前数据 ...
- java日志
http://blog.csdn.net/u013628152/article/details/43538299 http://blog.csdn.net/isea533/article/detail ...
- make是如何工作的
在默认的方式下,也就是我们只输入make命令.那么,1.make会在当前目录下找名字叫“Makefile”或“makefile”的文件.2.如果找到,它会找文件中的第一个目标文件(target),在上 ...
- Camera2点击对焦实现2
https://www.aliyun.com/jiaocheng/22218.html 阿里云 > 教程中心 > android教程 > Camera2点击对焦实现 Cam ...
- Django之404、500、400错误处理
要自定义处理url请求错误需要进行三步操作:主要错误有: 404错误:page not found视图 500错误:server error视图 400错误:bad request视图 以404错误为 ...
- centos6编译安装mysql5.5
常规编译安装:./configure;make;make install centos 6.5,安装mysql 5.5.54,所需安装包cmake-2.8.8.tar.gz.mysql-5.5.54. ...
- python2.7安装mysql-python
环境:python2.7.14+mysql-python-1.2.3.win-amd64-py2.7.exe 安装版本许参照解释器版本,有64和32位之分,如果安装错误版本,则运行时会报错:Impor ...
- 注册登录二合一之bootstrap
来源 https://bootsnipp.com/snippets/featured/login-and-register-tabbed-form jquery插件 需导入bootstrap插件 这个 ...
- centos/rhel 7 几个最重要变化(systemd,firewalld,networkmanager,文件系统)
详细参考:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administra ...
- 【题解】Luogu P1503 鬼子进村
平衡树好题 原题传送门 这道题要用Splay,我博客里有对Splay的详细介绍 这道题思维有点难,要把被摧毁的节点插入平衡树,而不是把没有摧毁的节点插入 先把0和n+1插入平衡树,作为边界 操作1:摧 ...