题目描述

题解:

树上删边。

$SG[u]$^=$SG[son[u]]+1$

代码:

#include<cstdio>
#include<cstring>
const int N = ;
template<typename T>
inline void read(T&x)
{
T f = ,c = ;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){c=c*+ch-'';ch=getchar();}
x = f*c;
}
int T,n,hed[N],cnt;
struct EG
{
int to,nxt;
}e[*N];
void ae(int f,int t)
{
e[++cnt].to = t;
e[cnt].nxt = hed[f];
hed[f] = cnt;
}
int dfs(int u,int f)
{
int ret = ;
for(int to,j=hed[u];j;j=e[j].nxt)
if((to=e[j].to)!=f)ret^=(dfs(to,u)+);
return ret;
}
int main()
{
read(T);
while(T--)
{
memset(hed,,sizeof(hed));
cnt=;
read(n);
for(int f,t,i=;i<n;i++)
{
read(f),read(t);
ae(f,t),ae(t,f);
}
puts(dfs(,)?"Alice":"Bob");
}
return ;
}

hdu3094 A tree game的更多相关文章

  1. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  2. SAP CRM 树视图(TREE VIEW)

    树视图可以用于表示数据的层次. 例如:SAP CRM中的组织结构数据可以表示为树视图. 在SAP CRM Web UI的术语当中,没有像表视图(table view)或者表单视图(form view) ...

  3. 无限分级和tree结构数据增删改【提供Demo下载】

    无限分级 很多时候我们不确定等级关系的层级,这个时候就需要用到无限分级了. 说到无限分级,又要扯到递归调用了.(据说频繁递归是很耗性能的),在此我们需要先设计好表机构,用来存储无限分级的数据.当然,以 ...

  4. 2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>

    在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000Things You Should Know About C# 和 2,0 ...

  5. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  6. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  7. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  8. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  9. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

随机推荐

  1. (水题)Codeforces - 650A - Watchmen

    http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...

  2. combobox级联检索下拉选择框

    1.效果图 2.前端 @{ ViewBag.Title = "Index"; Layout = null; @*自动筛选下拉框*@ <script src="~/S ...

  3. GoAhead4.1.0 开发总结三(GoAction+Ajax实现局部数据交互)

    环境 官方文档:https://www.embedthis.com/goahead/doc/ 源码下载: goahead-4.1.0-src.tgz 系统平台:Ubuntu 12.04.4 gcc v ...

  4. 命令行运行Java程序时出现错误

    在命令行运行Java程序时出现下面错误 Error: Could not create the Java Virtual Machine. Error: A fatal exception has o ...

  5. JSP文件过大无法编译

    JSP文件过大无法编译: The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding th ...

  6. Zernike矩之图像重建(附源码)

    源码下载 参考: [1] Teague M R. Image analysis via the general theory of moments[J]. JOSA, 1980, 70(8): 920 ...

  7. java 反向工具类

    1.ReflectUtil.java package com.example.scansell; import android.util.Log; import java.lang.reflect.C ...

  8. h5-16-SVG 与 HTML5 的 canvas 各自特点

    1. Canvas是使用JavaScript程序绘图(动态生成),SVG是使用XML文档描述来绘图.2.SVG更适合用来做动态交互,而且SVG绘图很容易编辑,只需要增加或移除相应的元素就可以了.同时S ...

  9. awr 收集时间

    windows 收集 awr 报告,一分钟一个.

  10. zoj3772Calculate the Function(矩阵+线段树)

    链接 表达式类似于斐波那契 但是多了一个变量 不能用快速幂来解 不过可以用线段树进行维护 对于每一个点够一个2*2的矩阵 1 a[i] 1  0   这个矩阵应该不陌生 类似于构造斐波那契的那个数列 ...