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

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
F先走,S后走,且只能走相邻的点,所以,bfs搜索所有的点,s可以走的点不少于f是就获胜
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
vector<int>v[];
int x,y,n;
int ans[]={,,};
int vis[];
void bfs(int x,int y)
{
mem(vis);
vis[x]=;
vis[y]=;
queue<int>q;
q.push(x);
q.push(y);
while(!q.empty())
{
int pos=q.front();
ans[vis[pos]]++;
q.pop();
for(int i=;i<v[pos].size();i++)
{
if(vis[v[pos][i]]) continue;
vis[v[pos][i]]=vis[pos];
q.push(v[pos][i]);
}
}
}
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&x,&y);
v[y].push_back(x);
v[x].push_back(y);
}
bfs(,n);
puts(ans[]>=ans[]?"Snuke":"Fennec");
}

AtCoder Beginner Contest 067 D - Fennec VS. Snuke的更多相关文章

  1. AtCoder Beginner Contest 067 C - Splitting Pi

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

  2. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  5. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  6. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  7. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  8. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  9. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

随机推荐

  1. 小A点菜 水题 dp 背包

    基本上还是01背包,首先注意必须正好花光钱,所以初始化时除了dp[0]以外其他都要设置成inf,然后因为求方案数,所以基本方程为dp[i] = dp[i-x] + dp[i],再根据inf进行一些特殊 ...

  2. Domino 使用递归算法获取视图值

    在关系数据库中,有两字段是父子关系.通过递归算法,输入一个父ID,能够获取全部相应的子ID.这种数据结构在组织架构中常常使用.显示一般使用树形结构.在Domino中相同能够处理这种情况,下面是个小de ...

  3. [BZOJ3884] 上帝与集合的正确用法 (欧拉函数)

    题目链接:  https://www.lydsy.com/JudgeOnline/problem.php?id=3884 题目大意: 给出 M, 求 $2^{2^{2^{2^{...}}}}$ % M ...

  4. BZOJ 3524主席树裸题 (雾)

    思路: 按权值建一棵主席树 (但是这好像不是正解 空间复杂度是不对的--.) //By SiriusRen #include <cstdio> #include <cstring&g ...

  5. 集合 List和Set

    分别向Set集合以及List集合中添加“A”,“a”,“c”,“C”,“a”5个元素,观察重复值“a”能否在List集合以及Set集合中成功添加. List<String> ls=new ...

  6. 请问Typecho Mysql 数据库和Sqlite数据库我该如何选择。

    纠结如我,又纠结了,请大家帮忙看一下我该如何选择.就一个没有文章的博客.一直用VPS太浪费,现在换成了虚拟主机.但是虚拟主机的MYSQL数据库限制连接数30个,我不懂这是个什么概念,但是我觉得30太少 ...

  7. BootStrap--panel面板

    1 <div class="panel panel-default"> <div class="panel-body"> 这是一个基本的 ...

  8. bzoj 2287: 【POJ Challenge】消失之物 动态规划

    Code: #include<cstdio> #include<algorithm> #include<queue> #include<cstring> ...

  9. DedeCMS文章编辑不更新时间1970年1月1日

    在修改文章或者后期优化的时候,织梦dedecms5.7版本存在一个问题,修改文章的同时也修改了文章的发布时间,这个功能可能有些人比较需要,但同时也有些站长朋友又不需要,因为我们编辑某个文章的时候,发现 ...

  10. Windows下使用VS的ADO访问MySQL

    数据库的访问的一种方式就是:CS结构.即使用TCP/UDP协议进行远程访问,而数据库对于服务端的软件是本地访问!这种管理方式比较常见. 这里主要叙述Windows访问本地数据库的方法. 需要了解几个概 ...