题目描述

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. 1568: [JSOI2008]Blue Mary开公司(超哥线段树)

    1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1198  Solved: 418 Descr ...

  2. hdu1950Bridging signals(求最长上升自序列nlogn算法)

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. Android使用Glide加载Gif.解决Glide加载Gif非常慢问题

    在Glide文档中找了半天没发现加载Gif的方式.然后通过基本的用法去加载: Glide.with(MainActivity.this).load(url).asGif().into(imageVie ...

  4. SQLAlchemy Script

    SQLAlchemy: 1.由于sqlalchemy中没有提供choice方法,所以借助SQLAlchemy-Utils组件提供的choice方法 from sqlalchemy_utils impo ...

  5. leetcode 【 Reverse Words in a String 】python 实现

    题目: Given an input string, reverse the string word by word. For example,Given s = "the sky is b ...

  6. Monkey官方帮助翻译&介绍

    都说想学好就看原文,英文不好为了翻译这个可费了大劲了.表格从GOOGLE官网复制到WORD里编辑,结果贴上来格式全乱了,只得不弄表格了.表格中官网的事件不是最新的,比最新的少2个,具体我会另发一篇文章 ...

  7. Github问题An error occurred trying to download

    Github for windows安装过程出现了这样的问题An error occurred trying to download 'http://github-windows.s3.amazona ...

  8. Leetcode 576.出界的路劲数

    出界的路径数 给定一个 m × n 的网格和一个球.球的起始坐标为 (i,j) ,你可以将球移到相邻的单元格内,或者往上.下.左.右四个方向上移动使球穿过网格边界.但是,你最多可以移动 N 次.找出可 ...

  9. redis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is configured to save RDB snapshots

    最近在学习Redis ,在写test测试的时候碰到这个报错: redis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is c ...

  10. linux 相关知识

    在mac 终端中可以直接访问ssh 命令:ssh root@127.0.0.*  批量删除文件: 当前目录下所有 *.html文件,除了index.html             [root@whr ...