hdu 3094 A tree game (树形删边游戏)
来源:互联网 发布:网络派出所电话 编辑:程序博客网 时间:2024/06/06 03:24
A tree game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 710 Accepted Submission(s): 386
Problem Description
Alice and Bob want to play an interesting game on a tree.
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.
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.
Input
The first line of the input file contains an integer T (T<=100) specifying the number of test cases.
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.
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.
Output
For each case, output a single line containing the name of the player who will win the game.
Sample Input
331 22 331 21 3 106 24 38 49 58 62 75 81 96 10
Sample Output
AliceBobAlice
Source
2009 Multi-University Training Contest 18 - Host by ECNU
Recommend
lcy | We have carefully selected several similar problems for you: 1907 2873 2509 1760 2147
题解:树形删边游戏
两点性质:1.所有叶节点的sg值为0
2.其他节点的sg值为他子节点的sg值+1的异或和。
证明来自贾志豪《组合游戏略述——浅谈SG游戏的若干拓展及变形》
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define N 200003using namespace std;int tot,n,m,point[N],nxt[N],v[N];void add(int x,int y){tot++; nxt[tot]=point[x]; point[x]=tot; v[tot]=y;tot++; nxt[tot]=point[y]; point[y]=tot; v[tot]=x;}int dfs(int x,int fa){int sg=0;for (int i=point[x];i;i=nxt[i]) if (v[i]!=fa) sg^=(dfs(v[i],x)+1);return sg;}int main(){scanf("%d",&m);for (int t=1;t<=m;t++) {scanf("%d",&n);tot=0;memset(point,0,sizeof(point));for (int i=1;i<n;i++){int x,y; scanf("%d%d",&x,&y);add(x,y);}int ans=dfs(1,0);if (ans) printf("Alice\n");else printf("Bob\n");}}
0 0
- 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
- hdu 3094 A tree game (博弈 树的删边问题)
- hdu3094 A tree game----树的删边游戏
- hdu3094—A tree game-(树形博弈)
- hdu 3094——A tree game
- poj 3710 Christmas Game (树形删边游戏)
- 【POJ3710】Christmas Game 博弈 有限制的图上删边游戏(树形删边游戏进化1)
- hdu 4863 Centroid of a Tree(树形dp)
- HDU 3904 A tree game题解
- hdu - 1054 - Strategic Game(树形dp)
- HDU 4616 Game (树形DP)
- hdu 4616 Game(树形dp)
- mac下挂在移动硬盘
- Linux字符驱动-scull
- 用python实现的可以自动补全的前缀树
- Go学习之遇到的第一大坑
- ionic添加cordova插件-NativeAudio
- hdu 3094 A tree game (树形删边游戏)
- swift UIProgressView
- 引用外部.css或.js文件的路径问题
- ifconfig, route以及ip指令的实战应用
- Mysql 数据库学习 (一)数据库概述
- 数据报表导出Excel功能
- Spring Processing
- Power BI 客户端 安装 错误
- 微信开发之发送消息接口