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. 1005 Spell It Right(20 分)

    1005 Spell It Right(20 分) Given a non-negative integer N, your task is to compute the sum of all the ...

  2. hdu 1385 Minimum Transport Cost (Floyd)

    Minimum Transport CostTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  3. 【Leetcode 做题学算法周刊】第四期

    首发于微信公众号<前端成长记>,写于 2019.11.21 背景 本文记录刷题过程中的整个思考过程,以供参考.主要内容涵盖: 题目分析设想 编写代码验证 查阅他人解法 思考总结 目录 67 ...

  4. 搭建Nginx七层反向代理

    基于https://www.cnblogs.com/Dfengshuo/p/11911406.html这个基础上,在来补充下七层代理的配置方式.简单理解下四层和七层协议负载的区别吧,四层是网络层,负载 ...

  5. python获取随机验证码或者下发激活码

    http://stackoverflow.com/questions/2823316/generate-a-random-letter-in-python >>> import ra ...

  6. java常用简略语含义

    首先这些对象都应用都是一些单词的简称,也是一种应用思想,故其他语言也可以使用,在Java里比较常见这些对象吧.下面来一一解释. 一.POJO(Plain Ordinary Java Object). ...

  7. windows下自制动画层引擎 - 放两个demo

    一年前想写一个像cocoa那样,可以方便层动画开发的引擎,写着写着又逆向它的QuartzCore.framework,也就是CoreAnimation的底层,已经大半年没有搞windows这个引擎.大 ...

  8. scrapy_redis分布式爬虫

    文章来源:https://github.com/rmax/scrapy-redis Scrapy-Redis Documentation: https://scrapy-redis.readthedo ...

  9. Centos7編譯安裝LAMP平臺

    什麽是LAMP? 拆開看 L 就是Linux系統 A是Apache的縮寫 M.P則是MySQL和PHP的简写. 其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行 ...

  10. LaravelS - 基于Swoole加速Laravel/Lumen

    LaravelS LaravelS是一个胶水项目,用于快速集成Swoole到Laravel或Lumen,然后赋予它们更好的性能.更多可能性.Github 特性 内置Http/WebSocket服务器 ...