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. Vue基础系列(四)——Vue中的指令(上)

    写在前面的话: 文章是个人学习过程中的总结,为方便以后回头在学习. 文章中会参考官方文档和其他的一些文章,示例均为亲自编写和实践,若有写的不对的地方欢迎大家和我一起交流. VUE基础系列目录 < ...

  2. 基于docker搭建Jenkins+Gitlab+Harbor+Rancher架构实现CI/CD操作(续)---Harbor的安装

    前期安装文档:https://www.cnblogs.com/lq-93/p/11828626.html Harbor的作用:     开发提交代码至gitlab容器中,Jenkins拉取代码构建镜像 ...

  3. Docker学习-Docker搭建Consul集群

    1.环境准备 Linux机器三台 网络互通配置可以参考 https://www.cnblogs.com/woxpp/p/11858257.html 192.168.50.21 192.168.50.2 ...

  4. vue根据不同环境进行编译打包

    工作中我们在开发过程中,有很多的开发环境,如果我们不进行统一配置,那么我们只能手动进行更改,这样会给我们带来诸多不便,所以我们要配置根据不同的环境来进行编译打包. 先看一下我的项目目录: 在confi ...

  5. .NET Core 3 WPF MVVM框架 Prism系列之数据绑定

    一.安装Prism 1.使用程序包管理控制台 Install-Package Prism.Unity -Version 7.2.0.1367 也可以去掉‘-Version 7.2.0.1367’获取最 ...

  6. VS Code 之 Jupyter NoteBook 初试

    一.前言 在今年九月的 PyCon China 大会上,官宣了一项 VS Code Python 的全新功能:Visual Studio Code Python 插件将提供 Jupyter Noteb ...

  7. 网络图片的获取以及二级缓存策略(Volley框架+内存LruCache+磁盘DiskLruCache)

    在开发安卓应用中避免不了要使用到网络图片,获取网络图片很简单,但是需要付出一定的代价——流量.对于少数的图片而言问题不大,但如果手机应用中包含大量的图片,这势必会耗费用户的一定流量,如果我们不加以处理 ...

  8. 超速入门AT指令集 | 我的物联网成长记

    [摘要] 在物联网中,AT命令集可用于控制&调测设备.通信模块入网等.本文为您介绍NB-IoT常用的AT命令集及其调测工具. 什么是AT指令集 AT命令,用来控制TE(Terminal Equ ...

  9. 阿里云:uwsgi--配置出错 bind(): Address already in use [core/socket.c line 769]

    按照网上配置nginx+uwsgi+django的文章,nginx启动成功,django启动也成功,单独用uwsgi --http :8000 命令启动uwsgi也成功.使用uwsgi  --sock ...

  10. webapi跨域使用session

    在之前的项目中,我们设置跨域都是直接在web.config中设置的. 这样是可以实现跨域访问的.因为我们这边一般情况下一个webapi会有多个网站.小程序.微信公众号等访问,所以这样设置是没有问题的. ...