题目描述

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

分析:本题最优策略是尽量堵住对手,BFS扫到最后发现谁占据的节点多,谁就会赢。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,x,y,col[],cnt[];
vector<int> map[];
void init(){
cin>>n;
range(i,,n-){
cin>>x>>y;
map[x].push_back(y);
map[y].push_back(x);
}
col[]=,col[n]=;
}
void solve(){
queue<int>q;
q.push(),q.push(n);
while(!q.empty()){
int head=q.front();
q.pop();
++cnt[col[head]];
range(i,,map[head].size()-){
int tmp=map[head][i];
if(col[tmp])continue;
col[tmp]=col[head];
q.push(tmp);
}
}
cout<<(cnt[]<cnt[]?"Fennec":"Snuke")<<endl;
}
int main() {
init();
solve();
return ;
}

Fennec VS. Snuke --AtCoder的更多相关文章

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

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

  2. 【AtCoder078D】Fennec VS. Snuke

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

  3. Fennec VS. Snuke

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

  4. ABC Fennec VS. Snuke

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

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

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

  6. AtCoder Regular Contest 078

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

  7. 【AtCoder】ARC078

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

  8. AtCoder Regular Contest 078 D

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

  9. すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)

    Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. ...

随机推荐

  1. RCP 主题切换

    第一步 编写css文件,放到项目目录下 第二步 添加切换主题扩展点 第三步 设置主题   public  void switchTheme(String themeID) {           Bu ...

  2. Android Studio 快捷键(包含自定义)终极版

      [F] [F] F2 在错误代码之间切换 F3 往前定位(Shift + F3:往后定位 )有问题 F4\Ctrl+鼠标点击\Ctrl+B 转到定义,查看类继承关系 F5 但不调试进入函数内部. ...

  3. CQRS之旅——旅程3(订单和注册限界上下文)

    旅程3:订单和注册限界上下文 CQRS之旅的第一站 "寓言家和鳄鱼是一样的,只是名字不同" --约翰·劳森 描述: 订单和注册上下文有一部分职责在会议预订的过程中,在此上下文中,一 ...

  4. 1 django

    1.MVC 大部分开发语言中都有MVC框架 MVC框架的核心思想是:解耦 降低各功能模块之间的耦合性,方便变更,更容易重构代码,最大程度上实现代码的重用 m表示model,主要用于对数据库层的封装 v ...

  5. 关于RelativeLayout设置垂直居中对齐不起作用的问题

    直接上代码 1.原有代码:(红色字体部分不起作用,无法让RelativeLayout中的textview居中) <RelativeLayout Android:id="@+id/aut ...

  6. easyui的layout

    1.浏览器自适应(即浏览器改变大小,里面的表格大小也会随之改变)要设置两个参数 (1)一般都要在body上设置class=“easyui-layout”: <body class="e ...

  7. Spring Boot 学习系列(03)—jar or war,做出你的选择

    此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 两种打包方式 采用Spring Boot框架来构建项目,我们对项目的打包有两种方式可供选择,一种仍保持原有的 ...

  8. alert(1) to win部分解题

    XSS在线习题分析 (https://alf.nu/alert1) 1. Warmup function escape(s) { return '<script>console.log(& ...

  9. python-day3-内置函数与字符字节之间的转换

    #三元运算 1 if True else 0 >>>1 1 if False else 0 >>>0 #内置函数lambda def f1(a1): return ...

  10. PDF文件加密怎么转换成word

    1.将文档拖入Chrome浏览器 2. 3.右上角打印,然后会提示 另存为本地,然后再用word或者福昕套件转换就行