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 N1 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

  • 2N105
  • 1ai,biN
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

Na1 b1:aN1 bN1

Output

If Fennec wins, print Fennec; if Snuke wins, print Snuke.


Sample Input 1

Copy
73 61 23 17 45 71 4

Sample Output 1

Copy
Fennec

For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.


Sample Input 2

Copy
41 44 22 3

Sample Output 2

Copy
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");
}

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 护照还在大使馆需要出国怎么办 护照在大使馆不返回怎么办 美国面签迟到了怎么办 成都美签迟到了怎么办 签证电调没人接怎么办 单位没有抬头纸怎么办在职证明 出国签证无银行流水怎么办 铁路职工得癌症后工作怎么办 去泰国不会泰语和英语怎么办 签证状态一直没有更新怎么办 简理财不能身份信息确认怎么办 德国领事馆没有收到预约邮件怎么办 父母一方带孩子英国签证怎么办 去韩国自由行签证怎么办 韩国自由行签证的该怎么办 法院离婚判决书没了怎么办 离婚判决书对方没收到怎么办 法院判离怎么办离婚证 判决书下来后没钱还怎么办 拿调解书怎么办离婚证 判决书生效后对方拒不履行怎么办 收到民事判决公告该怎么办 苹果手机gps信号弱怎么办 二审败诉后拿到判决书怎么办 农商行房贷逾期一天怎么办 农商行房贷逾期怎么办 农发行车改司机怎么办 混泥土地泵排量不稳怎么办 改嫁上海老公孩子的户口怎么办 给小孩办社保卡怎么办 有上海居住证积分怎么办医保 未办理居住证积分新生儿医保怎么办 厦门中考居住证没满三年怎么办 海归落户过了两年期怎么办 借呗学历填错了怎么办 上海落户应届生分不够怎么办 应届生落户分数不够72分怎么办? 上海应届生落户时间延误怎么办 南京市区户口签江宁怎么办 深圳公司集体户口离职后怎么办 济南本地户口不符合入学条件怎么办