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:

  1. N
  2. a1 b1
  3. :
  4. aN1 bN1

Output

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


Sample Input 1

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

Sample Output 1

Copy
  1. Fennec

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


Sample Input 2

Copy
  1. 4
  2. 1 4
  3. 4 2
  4. 2 3

Sample Output 2

Copy
  1. Snuke
    题意:有一颗树,第一个点颜色为1,最后一点颜色为2,1颜色可以将它相邻的点染色成1颜色,2颜色同理,现在F先手,S后手,最后不能染色算输,最后谁赢了
    解法:
    1 F开始染色第1点和它周围点(ABC....),然后S开始染色第N点和它周围点(abc..),然后F染色A点和A点相邻点,然后S染色a点和a点相邻点...
    2 明白了吗?最后谁染色的点多谁就赢了
    3 这里染色讲究先后,我们用队列广搜
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4. #include <queue>
  5. #define N 100005
  6. using namespace std;
  7. vector <int> vec[N];
  8. int color[N];
  9. int main(){
  10. queue <int> que;
  11. int n , x , y;
  12. scanf("%d",&n);
  13. for(int i = ; i < n ; i ++){
  14. scanf("%d%d",&x,&y);
  15. vec[x].push_back(y);
  16. vec[y].push_back(x);
  17. }
  18. color[] = , color[n] = ;
  19. int cnt[] = { , };
  20. que.push() ;
  21. que.push(n);
  22. while(!que.empty()){
  23. int x = que.front();
  24. que.pop();
  25. cnt[color[x]] ++;
  26.  
  27. for(int i = ; i < vec[x].size() ; i ++){
  28. int v = vec[x][i];
  29. if(color[v]) continue;
  30. color[v] = color[x];
  31. que.push(v);
  32. }
  33. }
  34. if(cnt[] >= cnt[]){
  35. printf("Snuke\n");
  36. }else{
  37. printf("Fennec\n");
  38. }
  39.  
  40. }

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. 基于Appium、Python的自动化测试

    基于Appium.Python的自动化测试环境部署和实践   第一章 导言 1.1 编制目的 该文档为选用Appium作为移动设备原生(Native).混合(Hybrid).移动Web(Mobile ...

  2. Gym - 101147E E. Jumping —— bfs

    题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离. ...

  3. Derived 派生类

    #include "stdafx.h"#include "iostream" using namespace std; class Base1{public: ...

  4. 并不对劲的BJOI2019

    一些感想 现实并非游戏,并不支持反复刷关 猎人和防御工事一起被老山龙摧毁了: 猎人惨死雨中,结云村永无放晴之日: 猎人被狂龙病毒侵蚀,天空山上黑蚀龙泛滥. 好像这才是怪物猎人系列的真实结局呢 day ...

  5. AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(七)

    版本六中存在一个显著问题是: 当exe文件生存之后,运行的时候,通过consoleWrite函数打印出来的数据是无法展示出来的.这就存在一个问题:当运行失败的时候,我还是看不到任何log信息. 于是, ...

  6. EntityFrameWork Parameter '@columnType' must be defined.

    环境: EntityFrameWork  CodeFirst+MySql 今天在提交一个外键字段的修改时报“Parameter '@columnType' must be defined.” goog ...

  7. shell json简单处理

  8. 性能测试之Jmeter学习(四)

    本节主要讲解:如何创建Web测试计划 如何创建一个简单的测试计划,用于测试web站点? 1.明确测试需求:我们会模拟5个并发用户,对Jakarta Web站点的网个页面进行访问,另外每个并发用户都会运 ...

  9. vector 大小

    vector定义以后就最好确定大小resize(),否则在vector析构时可能出现 "double free or corruption"这样的错误

  10. g2o待总结

    http://blog.csdn.net/u010566411/article/details/53862601