题目描述

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 is given from Standard Input in the following format:
N
a1 b1
:
aN−1 bN−1

输出

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

样例输入

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

样例输出

Fennec

提示

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

思维题

题意:有一棵树,编号1~n,1为黑色,n为白色,其余尚未染色,Fennec先开始染黑色相邻的点,Snuke后染白色相邻的点,

交替反复,谁无法染色谁就输,二者都采取最优策略,问最后的胜者。

最优解就是尽可能把路堵住,把相邻的两个点染色,这样只有两种颜色染色点中间是互争的,其他的则为该染色点的势力范围。

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int s[maxn];
int aans,bans;
vector<int>vt[maxn];
int main(){
int n,x,y;
ios::sync_with_stdio(false);
cin.tie();
cin>>n;
for(int i=;i<n;i++){
cin>>x>>y;
vt[x].push_back(y);
vt[y].push_back(x);
}
queue<int>q;
s[]=;
s[n]=;
q.push();
q.push(n);
while(!q.empty())
{
int temp=q.front();
q.pop();
for(int i=;i<vt[temp].size();i++){
if(s[vt[temp][i]]) continue;
if(s[temp]==)
aans++;
else bans++;
s[vt[temp][i]]=s[temp];
q.push(vt[temp][i]);
}
}
if(bans>=aans) cout<<"Snuke"<<endl;
else cout<<"Fennec"<<endl;
return ;
}

ABC Fennec VS. Snuke的更多相关文章

  1. 【AtCoder078D】Fennec VS. Snuke

    AtCoder Regular Contest 078 D - Fennec VS. Snuke 题意 给一个树,1是白色,n是黑色,其它没有颜色.Fennec每次可以染白色点的直接邻居为白色.Snu ...

  2. Fennec VS. Snuke

    Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement Fenne ...

  3. Fennec VS. Snuke --AtCoder

    题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...

  4. AtCoder Beginner Contest 067 D - Fennec VS. Snuke

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  5. ARC078 D.Fennec VS. Snuke(树上博弈)

    题目大意: 给定一棵n个结点的树 一开始黑方占据1号结点,白方占据n号结点 其他结点都没有颜色 每次黑方可以选择黑色结点临近的未染色结点,染成黑色 白方同理. 最后谁不能走谁输. 题解: 其实简单想想 ...

  6. AtCoder Regular Contest 078 D

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  7. AtCoder Regular Contest 078

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

  8. 【AtCoder】ARC078

    C - Splitting Pile 枚举从哪里开始分的即可 #include <bits/stdc++.h> #define fi first #define se second #de ...

  9. 【思维】ABC

    题目描述 You are given a string s consisting of A, B and C.Snuke wants to perform the following operatio ...

随机推荐

  1. JavaScript 之 数据在内存中的存储和引用

    栈和堆 大家都知道,JS中的数据类型包括两种:简单数据类型(String.Number.Boolean.undefined.null)和复杂数据类型(object). 在内存中分为栈区(stack)和 ...

  2. python 设置系统/用户环境变量

    系统环境变量 winreg.HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' 用户环境变 ...

  3. 吴裕雄--天生自然 PHP开发学习:Switch 语句

    <?php $favcolor="red"; switch ($favcolor) { case "red": echo "你喜欢的颜色是红色! ...

  4. c语言中%s和%d的区别

    /************************************************************************* > File Name: ptr_both. ...

  5. Maven--超级 POM

    对于 Maven3,超级 POM 在文件 %MAVEN_HOME%/lib/maven-model-builder-x.x.x.jar 中的 org/apache/maven/model/pom-4. ...

  6. Java8之深入理解Lambda

    lambda表达式实战 从例子引出lambda 传递Runnable创建Thread java8之前 Thread thread=new Thread(new Runnable() { @Overri ...

  7. @EnableWebMvc WebMvcConfigurer

    Spring注解@EnableWebMvc使用坑点解析 https://blog.csdn.net/zxc123e/article/details/84636521 @EnableWebMvc,Web ...

  8. 吴裕雄--天生自然TensorFlow2教程:numpy [ ] 索引

    import tensorflow as tf a = tf.ones([1, 5, 5, 3]) a.shape a[0][0] numpy : 索引 a = tf.random.normal([4 ...

  9. ZJNU 1538 - YN!ngC的取子游戏--高级

    Nim博弈 因为移动到第0阶会消失 所以可以得到从最后一个人操作必定是把第1阶所有子全部移动到第0阶 递推可得,最后一个能把奇数阶的子移动到偶数阶上的人将会必胜 所以这个必胜条件就是奇数阶上的子全部为 ...

  10. Tensorflow学习教程------lenet多标签分类

    本文在上篇的基础上利用lenet进行多标签分类.五个分类标准,每个标准分两类.实际来说,本文所介绍的多标签分类属于多任务学习中的联合训练,具体代码如下. #coding:utf-8 import te ...