题目描述

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. Maven:Failure executing javac, but could not parse the error:javac: 无效的目标发行版: 1.8

    eclipse中对着项目maven——>>maven install时出现错误:Failure executing javac, but could not parse the error ...

  2. PHP+InfiniteScroll实现网页无限滚动加载数据实例

    PHP+InfiniteScroll实现网页无限滚动加载数据实例,实现原理:当滚动条到底离网页底部一定长度的时候,向后台发送页数并获取数据. 首先我们在页面上先放置10条数据,即第一页,每一项都是p标 ...

  3. UVA-101 The Blocks Problem 栈模拟

    终于AC了,这道题目去年寒假卡得我要死,最后一气之下就不做了...想想居然一年之久了,我本来都快忘了这道题了,最近发现白书的奥秘,觉得刘汝佳的题目真的相当练思维以及对代码的操作,决定又刷起题目来,这时 ...

  4. 当切换用户时出现-bash-4.1$

    问题重现 [root@localhost ~]# su - yh -bash-4.1$ -bash-4.1$ -bash-4.1$ -bash-4.1$ -bash-4.1$ cd /home -ba ...

  5. 吴裕雄--天生自然MySQL学习笔记:MySQL 创建数据表

    创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (column_name col ...

  6. 2020/1/28 PHP代码审计之命令执行漏洞

    0x00 命令执行漏洞原理 应用程序有时需要调用一些执行系统命令的函数,如在PHP中,使用system.exec.shell_exec.passthru.popen.proc_popen等函数可以执行 ...

  7. 编程作业3.1:Multi-class classification(One-vs-all)

    题目: 在本次练习中,你将使用逻辑回归和神经网络来识别手写数字(从0到9). 今天,自动手写数字识别被广泛使用,从识别信封上的邮政编码到识别银行支票上的金额.这个练习将向你展示如何将你所学的方法用于此 ...

  8. Mybatis学习——Mybatis入门程序

    MyBatis入门程序 一.查询用户 1.使用客户编号查询用户 (1).创建一个数据表 USE spring; #创建一个名为t_customer的表 CREATE TABLE t_customer( ...

  9. springCloud 常用组件总结

    本文浅谈只是对我自己初期认识这spring cloud的一个笔记. 微服务是一种架构风格和一种应对业务的架构策略.实现这种的技术方式很多.本文主要说spring cloud. spring cloud ...

  10. [LC] 51. N-Queens

    Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a d ...