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

AtCoder Regular Contest 078 D的更多相关文章

  1. AtCoder Regular Contest 078

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

  2. AtCoder Regular Contest 078 C

    C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...

  3. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  4. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  5. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  6. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  7. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

  8. AtCoder Regular Contest 095

    AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...

  9. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

随机推荐

  1. RobotFramework教程使用笔记——web自动化测试弹窗处理

    在web自动化测试中会遇到各种弹出框,在selenium中有对这些弹出框的处理. 弹出框一般有这么几类: 1.普通的弹出窗口,如果是可以定位的,直接定位到窗口,然后进行相应的操作. 2.如果是浏览器系 ...

  2. web安全字体

    webfont解剖 Unicode字体可以包含数以千计字形 有四个字体格式: WOFF2, WOFF, EOT, TTF 一些字体格式需要使用GZIP压缩 一个web字体是字形的集合,且每个字形是一个 ...

  3. SPOJ:Red John is Back(DP)

    Red John has committed another murder. But this time, he doesn't leave a red smiley behind. What he ...

  4. HDU1171(01背包均分问题)

    Big Event in HDU Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  5. bzoj5117

    线段树 先看前三个操作,都是区间修改,我们对于信息维护一个二元组(a,b),表示x=max(x+a,b),那么第一个操作就是(a,-inf),第二个是(-a,0),第三个是(-inf,a) 然后看查询 ...

  6. 关于try catch finally的执行顺序解释

    偶然遇到了被问到finally的执行问题,忽然发现一直用的都是try catch 没有用过finally的情况,所以目前总结一下. 先抛出结论: 1.try内部正常执行try的内部逻辑,异常则执行ca ...

  7. Firebug的安装与使用

    第一步,点击 Firefox 浏览器上的“工具”选项,然后点击“附加软件”,在弹出的小窗口中,点击右下角的“获取扩展”选项,如图 4 所示. 图 4. 获取扩展 第二步,在点击“获取扩展”选项后,打开 ...

  8. Python的中文处理

    一.使用中文字符 在python源码中如果使用了中文字符,运行时会有错误,解决的办法是在源码的开头部分加入字符编码的声明,下面是一个例子: #!/usr/bin/env python # -*- co ...

  9. json对象和json数组

    json字符串对象和json字符串数组:JSONArray跟JSONObject的区别就是JSONArray比JSONObject多中括号[] jsonObject: "Row": ...

  10. POJ - 2376 Cleaning Shifts 贪心(最小区间覆盖)

    Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some clea ...