AtCoder Beginner Contest 067 D
来源:互联网 发布:平湖市行知小学校长 编辑:程序博客网 时间:2024/06/06 17:12
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,bi≤N
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Na1 b1:aN−1 bN−1
Output
If Fennec wins, print Fennec
; if Snuke wins, print Snuke
.
Sample Input 1
73 61 23 17 45 71 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
41 44 22 3
Sample Output 2
Snuke
#include<iostream> #include<cstdio>#include<stdio.h>#include<cstring>#include<cstdio>#include<climits> #include<cmath> #include<vector> #include <bitset> #include<algorithm> #include <queue> #include<map> #define inf 9999999; using namespace std; bool vis[100005];int sons[100005],father[100005],deep[100005],n;vector<int> tu[100005];void dfs(int son,int fa){int k;sons[son]=1;deep[son]=deep[fa]+1;father[son]=fa;for(int i=0;i<tu[son].size();i++){k=tu[son][i];if(k==fa) continue;if(vis[k]==0){vis[k]=1;dfs(k,son);sons[son]+=sons[k];}}} int main(){int i,x,y,tot;cin>>n;for(i=1;i<n;i++){cin>>x>>y;tu[x].push_back(y);tu[y].push_back(x);}memset(deep,0,sizeof(deep));memset(vis,0,sizeof(vis));vis[1]=1;dfs(1,0);tot=deep[n]-deep[1]-1;tot/=2;x=n;while(tot--)x=father[x];if(sons[x]>=n-sons[x]){cout<<"Snuke"<<endl;}else{cout<<"Fennec"<<endl;}}
- AtCoder Beginner Contest 067 D
- AtCoder Beginner Contest 067 D
- AtCoder Beginner Contest 061 D
- AtCoder Beginner Contest 066 D
- AtCoder Beginner Contest 068 D
- AtCoder Beginner Contest 069 D
- AtCoder Beginner Contest 070-D
- AtCoder Beginner Contest 070 D
- AtCoder Beginner Contest 071 D
- AtCoder Beginner Contest 075 D
- AtCoder Beginner Contest 076 D
- AtCoder Beginner Contest 081 D
- AtCoder Beginner Contest 081 D
- AtCoder AtCoder Beginner Contest 063 D
- AtCoder Beginner Contest 067 C
- AtCoder Beginner Contest 067 A
- AtCoder Beginner Contest 067 B
- AtCoder Beginner Contest 067 C
- 旁路电容、滤波电容、去耦电容的作用与应用原理详解
- web前端面试题-http协议
- 【Android编程架构】mvp架构
- Ubuntu 14.04 LTS下使用mips-linux-gnu-gcc交叉编译OpenCV所需库
- Apache2 安装错误 recipe for target 'all-recursive' failed
- AtCoder Beginner Contest 067 D
- Didn't find class "org.litepal.LitePalApplication" on path
- P1070 新年趣事之游戏
- Interllij idea使用
- 数据库连接池的理解
- mongodb常用语句
- java-正则表达式
- 整理一些图论的算法
- 前端流行使用的五种框架对比