Fennec VS. Snuke


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

Fennec and Snuke are playing a board game.

On the board, there are N cells numbered 1 through N, and N−1 roads, each connecting two cells. Cell ai is adjacent to Cell bi through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.

Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:

  • Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black.
  • Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white.

A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Constraints

  • 2≤N≤105
  • 1≤ai,bi≤N
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a1 b1
:
aN−1 bN−1

Output

If Fennec wins, print Fennec; if Snuke wins, print Snuke.


Sample Input 1

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

Sample Output 1

Fennec

For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.


Sample Input 2

4
1 4
4 2
2 3

Sample Output 2

Snuke

//n个格子,编号为1-n,1开始是黑色,n开始是白色。有m条边,且为树,说明格子的相邻情况,然后Fnc先开始涂黑色,涂色规则是:格子没被涂过色,并且相邻有黑色格子
然后Snu涂色,类似的规则,snu涂白色,相邻要有白色。轮流涂色,直到有一方不能涂了,另一方获胜。 显然,他们玩游戏会采取这样的策略,fnc先向着n点去涂色,snu向着1点去涂色,这样可以尽可能获得更多的地盘,然后就是比谁的地盘大咯
用神奇DFS实现
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 100010 int n;
int total;
vector<int> G[MX];
int colr[MX]; void DFS(int x,int pre,int c,int &tot)
{
if (colr[x]==-c) return;
tot++;
for (int i=;i<G[x].size();i++)
if (G[x][i]!=pre)
DFS(G[x][i],x,c,tot);
} void dfs(int u,int pre,int s,int &ok)
{
if (u==n)
{
ok=s;
return;
}
for (int i=;i<G[u].size();i++)
{
if (ok) break;
if (G[u][i]!=pre)
dfs(G[u][i],u,s+,ok);
}
if (ok)
{
if (u!=&&s<=ok/) colr[u]=;
if (u!=n&&s>ok/) colr[u]=-;
}
return;
} int main()
{
scanf("%d",&n);
for (int i=;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
colr[]=; //hei
colr[n]=-;//bai int ok=;
dfs(,-,,ok);
/*
for (int i=1;i<=n;i++)
printf("%d ",colr[i]);
printf("\n");
*/ int num_1=;
DFS(,-,,num_1);
int num_2=;
DFS(n,-,-,num_2);
if (num_1-num_2>=)
printf("Fennec\n");
else
printf("Snuke\n");
return ;
}


Fennec VS. Snuke的更多相关文章

  1. 【AtCoder078D】Fennec VS. Snuke

    AtCoder Regular Contest 078 D - Fennec VS. Snuke 题意 给一个树,1是白色,n是黑色,其它没有颜色.Fennec每次可以染白色点的直接邻居为白色.Snu ...

  2. Fennec VS. Snuke --AtCoder

    题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...

  3. AtCoder Beginner Contest 067 D - Fennec VS. Snuke

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  4. ABC Fennec VS. Snuke

    题目描述 Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N ...

  5. ARC078 D.Fennec VS. Snuke(树上博弈)

    题目大意: 给定一棵n个结点的树 一开始黑方占据1号结点,白方占据n号结点 其他结点都没有颜色 每次黑方可以选择黑色结点临近的未染色结点,染成黑色 白方同理. 最后谁不能走谁输. 题解: 其实简单想想 ...

  6. AtCoder Regular Contest 078

    我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...

  7. 【AtCoder】ARC078

    C - Splitting Pile 枚举从哪里开始分的即可 #include <bits/stdc++.h> #define fi first #define se second #de ...

  8. AtCoder Regular Contest 078 D

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  9. Snuke's Subway Trip

    すぬけ君の地下鉄旅行 / Snuke's Subway Trip Time limit : 3sec / Memory limit : 256MB Score : 600 points Problem ...

随机推荐

  1. 微信小程序 - 更改button状态

    wxml <button class='yes-orders' style='{{status_css}}' bindtap='clickExpress'> {{statusOrders} ...

  2. centos 6.5 python2.6.6 zbar 安装

       经过数次折腾,终于搞明白了这个zbar的安装顺序.   1.先安装http://zbar.sourceforge.net/download.html 下的zbar,   2.python 安装z ...

  3. Data truncation: Data too long for column

    是字符集问题引起的,用show full fields from + 表名就可以看出你的列的编码格式把它改成GBK或者GB2312.uTF-8.如果还不行的话,把你表的编码格式也改成上面的编码格式,我 ...

  4. android 内部类的优化

    developer.android.com 文档中有一篇关于性能的文章,里面提到了内部类的使用.文章建议"对于私有内部类 使用 包訪问权限取代私有权限訪问", 这里说的是在内部类訪 ...

  5. BASE64Decoder的引用

    project---->properties--->Libraries--->JRE System Library--->Access rules--->Edit---& ...

  6. ibatis-java.lang.RuntimeException: Error setting property 'setFileSize'

    ibatis查询问题:      ibatis-java.lang.RuntimeException: Error setting property 'setFileSize'

  7. 调用getChildFragmentManager时出现的Bug

    异常: java.lang.IllegalStateException: Activity has been destroyed at android.support.v4.app.FragmentM ...

  8. [原创]FreeSWITCH命令:uuid_dual_transfer

    该篇文章主要介绍FreeSWITCH的API命令uuid_dual_transfer的用法. 命令介绍 该命令用于同时将两条腿进行转移,并且是可以转移到不同的方向. -USAGE: <A-des ...

  9. Atitit.java相比c#.net的优点 优缺点  v2 q330

    Atitit.java相比c#.net的优点 优缺点  v2 q330 1. 跨平台可在LINUX上,mac跑以外.主要如下: 1 2. IDE ECLIPSE(500m)是绿色的,换机器不用安装,C ...

  10. 过滤NSString中的Emoji

    有时候由于项目需求.要过滤NSString中的emoji. 比方下面情况: 要跟android互通,android假设还没做这方面的支持. 内容做为手机短信发出去. 思路例如以下,遍历NSString ...