D - Game on Tree


Time limit : 2sec / Memory limit : 256MB

Score : 1100 points

Problem Statement

There is a tree with N vertices numbered 1,2,…,N. The edges of the tree are denoted by (xi,yi).

On this tree, Alice and Bob play a game against each other. Starting from Alice, they alternately perform the following operation:

  • Select an existing edge and remove it from the tree, disconnecting it into two separate connected components. Then, remove the component that does not contain Vertex 1.

A player loses the game when he/she is unable to perform the operation. Determine the winner of the game assuming that both players play optimally.

Constraints

  • 2≤N≤100000
  • 1≤xi,yiN
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
x1 y1
x2 y2
:
xN−1 yN−1

Output

Print Alice if Alice wins; print Bob if Bob wins.


Sample Input 1

Copy
5
1 2
2 3
2 4
4 5

Sample Output 1

Copy
Alice

If Alice first removes the edge connecting Vertices 1 and 2, the tree becomes a single vertex tree containing only Vertex 1. Since there is no edge anymore, Bob cannot perform the operation and Alice wins.


Sample Input 2

Copy
5
1 2
2 3
1 4
4 5

Sample Output 2

Copy
Bob

Sample Input 3

Copy
6
1 2
2 4
5 1
6 3
3 2

Sample Output 3

Copy
Alice

Sample Input 4

Copy
7
1 2
3 7
4 6
2 3
2 4
1 5

Sample Output 4

Copy
Bob

在树上的博弈,从0,1开始看看这棵树的异或和

#include <bits/stdc++.h>
using namespace std;
const int N=;
vector<int>vec[N];
int dfs(int u,int fa) {
int re=;
for(int i=; i<vec[u].size(); i++) {
if(vec[u][i]!=fa) {
re^=+dfs(vec[u][i],u);
}
}
return re;
}
int main() {
int n;
scanf("%d",&n);
for(int i=; i<n; i++) {
int a,b;
scanf("%d%d",&a,&b);
vec[a].push_back(b);
vec[b].push_back(a);
}
printf(dfs(,)?"Alice\n":"Bob\n");
return ;
}

最新文章

  1. Git的冲突解决过程
  2. Web开发中管理ipad屏幕的方向变化
  3. css 导航,菜单对应页面切换效果实现方法
  4. synchronized锁自旋2
  5. 海康威视摄像头SDK-网页版(NetVideoActiveX23.cab安装)
  6. [hackerrank]Service Lane
  7. [iOS基础控件 - 6.12.3] @property属性 strong weak copy
  8. CoordinatorLayout的简单应用(材料设计新控件)
  9. win7安装gevent时报错 whl is not a supported wheel on this platform.
  10. Hadoop2.2编程:新旧API的区别
  11. jQuery 源码细读 -- $.Callbacks
  12. Android学习----AndroidManifest.xml文件解析
  13. Python学习日志(六)
  14. zoj1610(线段树)
  15. vue关于数组使用的坑
  16. 《前端之路》之 this 的使用技巧总结
  17. Java【第六篇】面向对象基础
  18. 为github公开项目单独设置用户名
  19. 个人作业 - Week3 - 案例分析
  20. IO、NIO、AIO

热门文章

  1. react中constructor和super()以及super(props)的区别。
  2. linux机器上部署多台Tomcat
  3. Memcached笔记之分布式算法
  4. js判断是否为app
  5. DROP LANGUAGE - 删除一个过程语言
  6. Mycat高可用解决方案二(主从复制)
  7. centos7.4进入单用户模式
  8. destoon公司账户增加销售区域等下拉列表配置
  9. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之fsm1各种style的timing/area比较
  10. Thinkphp5 获取执行的sql语句