Jolly and Emily are two bees studying in Computer Science. Unlike other bees they are fond of playing two-player games. They used to play Tic-tac-toe, Chess etc. But now since they are in CS they invented a new game that definitely requires some knowledge of computer science.

Initially they draw a random rooted tree (a connected graph with no cycles) in a paper which consists of n nodes, where the nodes are numbered from 0 to n-1 and 0 is the root, and the edges are weighted. Initially all the edges are unmarked. And an edge weigh w, has w identical units.

  1. Jolly has a green marker and Emily has a red marker. Emily starts the game first and they alternate turns.
  2. In each turn, a player can color one unit of an edge of the tree if that edge has some (at least one) uncolored units and the edge can be traversed from the root using only free edges. An edge is said to be free if the edge is not fully colored (may be uncolored or partially colored).
  3. If it's Emily's turn, she finds such an edge and colors one unit of it using the red marker.
  4. If it's Jolly's turn, he finds such an edge and colors one unit of it with the green marker.
  5. The player, who can't find any edges to color, loses the game.

For example, Fig 1 shows the initial tree they have drawn. The tree contains four nodes and the weights of the edge (0, 1), (1, 2) and (0, 3) are 1, 1 and 2 respectively. Emily starts the game. She can color any edge she wants; she colors one unit of edge (0 1) with her red marker (Fig 2). Since the weight of edge (0 1) is 1 so, this edge is fully colored.

Now it's Jolly's turn. He can only color one unit of edge (0 3). He can't color edge (1 2) since if he wants to traverse it from the root (0), he needs to use (0, 1) which is fully colored already. So, he colors one unit of edge (0 3) with his green marker (Fig 3). And now Emily has only one option and she colors the other unit of (0 3) with the red marker (Fig 4). So, both units of edge (0 3) are colored. Now it's Jolly's turn but he has no move left. Thus Emily wins. But if Emily would have colored edge (1 2) instead of edge (0 1), then Jolly would win. So, for this tree Emily will surely win if both of them play optimally.

Input

Input starts with an integer T (≤ 500), denoting the number of test cases.

Each case starts with a line containing an integer n (2 ≤ n ≤ 1000). Each of the next n-1 lines contains two integers u v w (0 ≤ u, v < n, u ≠ v, 1 ≤ w ≤ 109) denoting that there is an edge between u and and their weight is w. You can assume that the given tree is valid.

Output

For each case, print the case number and the name of the winner. See the samples for details.

Sample Input

4

4

0 1 1

1 2 1

0 3 2

5

0 1 1

1 2 2

0 3 3

0 4 7

3

0 1 1

0 2 1

4

0 1 1

1 2 1

1 3 1

Sample Output

Case 1: Emily

Case 2: Emily

Case 3: Jolly

Case 4: Emily

Note

Dataset is huge, use faster I/O methods.

题解:green博弈变形,对于都是1的就是green博弈SG[u]^=SG[v]+1;

对于大于1的边,偶数对其没有贡献,奇数有贡献,SG[u]^= SG[v]^(val[v]%2);

参考代码:

 #include<bits/stdc++.h>
using namespace std;
#define RI register int
#define clr(a,val) memset(a,val,sizeof(a))
typedef long long ll;
struct Edge{
int to,val,nxt;
} edge[];
int x,y,z;
int T,n,sum1,sum2,cnt;
int head[],SG[];
inline void addedge(int u,int v,int w)
{
edge[cnt].to=v;
edge[cnt].val=w;
edge[cnt].nxt=head[u];
head[u]=cnt++;
}
inline void dfs(int u,int fa)
{
SG[u]=;
for(int e=head[u];~e;e=edge[e].nxt)
{
int v=edge[e].to;
if(v==fa) continue;
dfs(v,u);
if(edge[e].val==) SG[u]^=(SG[v]+);
else SG[u]^=(SG[v]^(edge[e].val%));
}
}
int main()
{
scanf("%d",&T);
for(RI cas=;cas<=T;++cas)
{
scanf("%d",&n);
clr(head,-);cnt=;
for(RI i=;i<n;++i)
{
scanf("%d%d%d",&x,&y,&z);
addedge(x,y,z);addedge(y,x,z);
}
dfs(,);
if(SG[]) printf("Case %d: Emily\n",cas);
else printf("Case %d: Jolly\n",cas);
}
return ;
}

LightOJ1355 Game Of CS(green 博弈)的更多相关文章

  1. LightOJ 1355 :Game of CS(树上green博弈)

    Jolly and Emily are two bees studying in Computer Science. Unlike other bees they are fond of playin ...

  2. hihocoder1545 : 小Hi和小Ho的对弈游戏(树上博弈&nim博弈)

    描述 小Hi和小Ho经常一起结对编程,他们通过各种对弈游戏决定谁担任Driver谁担任Observer. 今天他们的对弈是在一棵有根树 T 上进行的.小Hi和小Ho轮流进行删除操作,其中小Hi先手. ...

  3. acm博弈论基础总结

    acm博弈论基础总结 常见博弈结论 Nim 问题:共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子,至少取一颗,至多取出这一 ...

  4. 【BZOJ 2688】 2688: Green Hackenbush (概率DP+博弈-树上删边)

    2688: Green Hackenbush Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 42  Solved: 16 Description   ...

  5. 全局程序集GlobalAssemblyInfo.cs进行版本控制(引)

    原文出自:http://blog.csdn.net/oyi319/article/details/5753311 1.全局程序集GlobalAssemblyInfo.cs 我们编写的一个解决方案,通常 ...

  6. silverlight 生产图表(动态图表类型,Y轴数量) .xaml.cs文件

    silverlight 页面后台方法 .xaml.cs文件 public void CreateChart(Grid oGrid, ObservableCollection<ListItem&g ...

  7. hdu4678 Mine 2013 Multi-University Training Contest 8 博弈题

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  8. Codeforces Round #417 (Div. 2)A B C E 模拟 枚举 二分 阶梯博弈

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

随机推荐

  1. day1-python初识以及变量

    一.变量:将输入的内容赋值给变量,即变量=输入的内容 n1=input('请输入用户名:') 二. 变量名可以是 -英文. -数字.数字不能开头 -下划线,但是不可以下划线开头 不能是关键字 'and ...

  2. oracle直接调用web services

    oracle调用C#开发web services 1,  去oracle官网上下载dbws-callout-utility-10131.zip 地址:https://oracle-base.com/a ...

  3. Dockerfile介绍及指令详情

    Dockerfile简介:   镜像的定制实际上就是定制每一层所添加的配置.文件.如果我们可以把每一层修改.安装.构建.操作的命令都写入一个脚本,用这个脚本来构建.定制镜像,那么哪些无法重复的问题.镜 ...

  4. Ansible之常用模块(一)

    ansible之所以功能强大,不是ansible本身,是因为它有众多的模块,前文我们介绍了ansible的基础介绍,系列命令的用法以及选项的说明,通过前文的学习我们知道了ansible是基于pytho ...

  5. Project Euler 60: Prime pair sets

    素数3, 7, 109, 673很有意思,从中任取两个素数以任意顺序拼接起来形成的仍然是素数.例如,取出7和109,7109和1097都是素数.这四个素数的和是792,是具有这样性质的四个素数的最小的 ...

  6. C# 操作本地用户和组(基本全功能)

    今天学习了下怎么用.Net操作本地用户和组,因为目前网上还没看到一篇比较完整的文章,所以整理了下也分享出来,最后附带参考文档,方便深究的童鞋继续学习.==========  原创作品    作者:Yo ...

  7. windows 激活工具链接

    链接:https://pan.baidu.com/s/1FphGFZhhLp01akGTDWjW2A  密码:f9t7

  8. 力扣(LeetCode)验证回文串 个人题解

    给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, a plan, a c ...

  9. 看淡生死,不服就干(C语言指针)

    看淡生死,不服就干 emmmmm 其实今天蛮烦的 高等数学考的一塌糊涂 会的不会的都没写 真心没有高中轻松了啊 也不知道自己立的flag还能不能实现 既然选择了就一定坚持下去啊 下面还是放一段之前写的 ...

  10. 新闻网页通用抽取器GNEv0.04版更新,支持提取正文图片与源代码

    GeneralNewsExtractor以下简称GNE是一个新闻网页通用抽取器,能够在不指定任何抽取规则的情况下,把新闻网站的正文提取出来. 我们来看一下它的基本使用方法. 安装 GNE 使用 pip ...