AtCoder Beginner Contest 067 D
来源:互联网 发布:js复制选中文字 编辑:程序博客网 时间:2024/06/06 07:25
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
题解:
F先走,S后走,且只能走相邻的点,所以,bfs搜索所有的点,s可以走的点不少于f是就获胜
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
vector<int>v[100006];
int x,y,n;
int ans[4]={0,0,0};
int vis[100006];
void bfs(int x,int y)
{
mem(vis);
vis[x]=1;
vis[y]=2;
queue<int>q;
q.push(x);
q.push(y);
while(!q.empty()){
int pos=q.front();
ans[vis[pos]]++;
q.pop();
for(int i=0;i<v[pos].size();i++){
if(vis[v[pos][i]]) continue;
vis[v[pos][i]]=vis[pos];
q.push(v[pos][i]);
}
}
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&x,&y);
v[y].push_back(x);
v[x].push_back(y);
}
bfs(1,n);
puts(ans[2]>=ans[1]?"Snuke":"Fennec");
}
- 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
- Java程序员应当知道的10个面向对象设计原则
- Android 获取应用SHA1码方法
- JavaWeb学习总结(四十六)——Filter(过滤器)常见应用
- WebView方法总结
- IDL中的plot函数
- AtCoder Beginner Contest 067 D
- 解题报告:Codeforces Round #362 (Div. 1) A. Lorenzo Von Matterhorn 树状概率DP
- 解析XML的方法
- ARM&THUMB
- Java基础——Java中各个包的功能
- 如何最高效学习探讨
- 【MR】MapReduce 1 与 MapReduce 2(YARN)框架对比
- java中参数的传递方式【值传递】
- java泛型详解