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 ;
}


最新文章

  1. 华硕笔记本U盘启动系统/WinPE报错。Windows failed to start. A Recent hardware or software change might be the cause.
  2. mvc DropDownList默认选项
  3. shell中&amp;&amp;和||的使用方法
  4. Code Hunters: Hello, world!
  5. HDU-1255 覆盖的面积 (扫描线)
  6. NOIP201305转圈游戏
  7. UVa 1593 (水题 STL) Alignment of Code
  8. android开发之Bundle使用
  9. C#--比较
  10. POJ2239_Selecting Courses(二分图最大匹配)
  11. listview的条目(item)如何做出卡片效果
  12. 在VirtualBox 虚拟机中安装CentOS7 64位实验基础系统
  13. Codeforces 777B Game of Credit Cards
  14. python_如何让字典保持有序?
  15. Spring Aop技术原理分析
  16. Linux 下安装idea,提示svn版本太低问题
  17. javascript库之Mustache库使用说明
  18. Maven 构建配置文件
  19. shell脚本变量$#,$*,$$,$@,$0,$1,$2,$?的含义
  20. Eigen库和STL容器冲突问题

热门文章

  1. Java 多线程之 synchronized 和 volatile 的比較
  2. 【翻译自mos文章】在Oracle单机数据库中定义database service
  3. lodash 类型判断
  4. nnlog-yaml
  5. Cron表达式中特殊字符解释
  6. C#实现的根据日期得到今天是星期几
  7. 傻瓜方法求集合的全部子集问题(java版)
  8. Mysql中处理1970年前的日期(unixtime为负数的情况)负数时间戳格式化
  9. Linux操作系统桌面环境GNOME和KDE的切换
  10. FPGA开发要懂得使用硬件分析仪调试——ILA