Problem:
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 a_i is adjacent to Cell b_i 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 \leq N \leq 10^5

1 \leq a_i, b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

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

Sample Input 1

7
3 6
1 2
3 1
7 4
5 7
1 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

4
1 4
4 2
2 3

Sample Output 2

Snuke

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::{stdin,Read};
use std::str::FromStr;
use std::mem;

fn main(){
    let n = read::<usize>();
    let mut lca = Lca::new(n+10,0);
    for i in 0..n-1{
        let a = read::<usize>()-1;
        let b = read::<usize>()-1;
        lca.add(a,b);
    }
    lca.exec();

    let dist = lca.dist(0,n-1);
    let mut v = vec![];
    let mut p = lca.par[n-1][0] as usize;
    while p != 0 {
        v.push(p);
        p = lca.par[p][0] as usize;
    }
    let mut col = vec![0;n];
    col[0] = 1;
    col[n-1] = 2;
    for i in 0..v.len()/2{
        col[v[i]] = 2;
    }
    for i in 0..v.len(){
        if col[v[i]]==0 {
            col[v[i]] = 1;
        }
    }
    //println!("{:?}",col);

    let cnt = lca.paint(&col,2*n,0,1);
    //println!("{}",cnt);
    
    if 2*cnt==n {
        println!("Snuke");
    }
    else if cnt < n - cnt{
        println!("Snuke");
    }else{
        println!("Fennec");
    }
}


// construct O(n)
// query O(logn)
#[allow(dead_code)]
struct Lca{
    e:Vec<Vec<usize>>,
    pub par:Vec<Vec<i32>>,
    dep:Vec<usize>,
    root:usize,
    n:usize
}
#[allow(dead_code)]
impl Lca{
    pub fn new( n:usize,root:usize)->Lca{
        Lca{e:vec![Vec::<usize>::new();n],par:vec![vec![-1;30];n],dep:vec![0;n],root:root,n:n}
    }
    fn add(&mut self,u:usize,v:usize){
        self.e[u].push(v);
        self.e[v].push(u);
    }
    fn paint(&self,col:&Vec<usize>,p:usize,u:usize,color:usize)->usize{
        let mut sum = 1;
        //println!("{}",u);
        for to in self.e[u].clone(){
            if p == to {
                continue;
            }
            if col[to] == 0 || col[to] == color {
                sum += self.paint(&col,u,to,color);
            }
        }
        sum
    }
    fn dfs(&mut self,v:usize,p:i32,d:usize){
        self.par[v][0] = p;
        self.dep[v] = d;
        for to in self.e[v].clone() {
            if to as i32 != p  
            {
                self.dfs(to,v as i32,d+1);
            }
        }
    }
    fn exec(&mut self){
        self.fill_depth();
        self.fill_table();
    }
    fn fill_depth(&mut self){
        let root = self.root.clone();
        self.dfs(root,-1,0);
    }
    fn fill_table(&mut self){
        self.par[0][0] = -1;
        for i in 0..20{
            for j in 0..self.n{
                if  self.par[j][i] == -1 {
                    self.par[j][i+1] = -1;
                } else {
                    self.par[j][i+1] = self.par[self.par[j][i] as usize][i];
                }
            }
        }
    }
    fn lca(&self,_u:usize,_v:usize)->usize{
        let mut u = _u.clone();
        let mut v = _v.clone();
        if self.dep[u] > self.dep[v]{
            mem::swap(&mut u,&mut v);
        }
        for i in (0..20).rev(){
            if ((self.dep[v] - self.dep[u] )>>i)&1==1{
                v = self.par[v][i] as usize;
            }
        }
        if u == v {
            u 
        }else{
        for i in (0..20).rev(){
            if self.par[u][i] != self.par[v][i]{
                u = self.par[u][i] as usize;
                v = self.par[v][i] as usize;
            }
        }
        self.par[u][0] as usize
        }
    }
    // dist of edge is 1
    fn dist(&self,u:usize,v:usize)->usize{
        self.dep[u]+self.dep[v] - 2*self.dep[self.lca(u,v)]
    }
}
#[allow(dead_code)]
fn read_str() -> Vec<char>{
    let s :String = read();
    s.chars().collect::<Vec<char>>()
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(|_| panic!("Faild to parse "))
}