D - 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,biN
  • 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

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

Sample Output 1

Copy
Fennec

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


Sample Input 2

Copy
4
1 4
4 2
2 3

Sample Output 2

Copy
Snuke
题意:有一颗树,第一个点颜色为1,最后一点颜色为2,1颜色可以将它相邻的点染色成1颜色,2颜色同理,现在F先手,S后手,最后不能染色算输,最后谁赢了
解法:
1 F开始染色第1点和它周围点(ABC....),然后S开始染色第N点和它周围点(abc..),然后F染色A点和A点相邻点,然后S染色a点和a点相邻点...
2 明白了吗?最后谁染色的点多谁就赢了
3 这里染色讲究先后,我们用队列广搜
 #include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#define N 100005
using namespace std;
vector <int> vec[N];
int color[N];
int main(){
queue <int> que;
int n , x , y;
scanf("%d",&n);
for(int i = ; i < n ; i ++){
scanf("%d%d",&x,&y);
vec[x].push_back(y);
vec[y].push_back(x);
}
color[] = , color[n] = ;
int cnt[] = { , };
que.push() ;
que.push(n);
while(!que.empty()){
int x = que.front();
que.pop();
cnt[color[x]] ++; for(int i = ; i < vec[x].size() ; i ++){
int v = vec[x][i];
if(color[v]) continue;
color[v] = color[x];
que.push(v);
}
}
if(cnt[] >= cnt[]){
printf("Snuke\n");
}else{
printf("Fennec\n");
} }

最新文章

  1. &lt;2016-1-28&gt;
  2. Ubuntu如何更新源
  3. 从WinCE到Linux
  4. Spring MVC的启动过程
  5. CSS选择器优先级
  6. UVA10304---(区间DP)
  7. C++ Primer Chapter 1
  8. PHP不显示报错了怎么办~
  9. wpf之DataTrigger 数据触发器
  10. App遍历探讨(含源代码)
  11. nginx从http跳转到https
  12. js中值的基本类型与引用类型,以及对象引用,对象的浅拷贝与深拷贝
  13. thinkphp 整合微信支付-简单粗暴
  14. Python自学:第二章 合并(拼接字符串)
  15. Javascript Image Slider 插件注册机
  16. C语言结构体在内存中的存储情况探究------内存对齐
  17. Pandas的排序和排名(Series, DataFrame) + groupby
  18. Specified VM install not found: type Standard VM, name jdk1.7
  19. 【Web】Struts之namespace
  20. c语言结构体可以直接赋值

热门文章

  1. 绝对定位(absolute)
  2. 数据结构之 字符串---字符串匹配(kmp算法)
  3. nginx-upsync-module安装
  4. 手写Future模式
  5. BZOJ_1296_[SCOI2009]粉刷匠_DP
  6. js遍历checkbox获取数据
  7. c语言中的# ## 可变参数宏 ...和_ _VA_ARGS_ _
  8. 2-2和2-3基本数据类型 &amp; 2-4基本数据类型详解 &amp; 3-1和3-2整形字面量值及变量声
  9. PHP文件操作功能函数大全
  10. 服务迁移之路 | Spring Cloud向Service Mesh转变