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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        List<List<Integer>> tree = new ArrayList<>();
        for (int i :IntStream.range(0, N-1).toArray()){
            tree.add(Arrays.asList(scan.nextInt(), scan.nextInt()));
        }

        List<Integer> path = dijkstra(tree, N);
        path.forEach(System.out::println);
        List<Integer> black = new ArrayList<>();
        int blackNum = path.size() / 2 + path.size() % 2;
        int forbidden = path.get(blackNum);
        int blackCount = count(tree,black,forbidden,N);
        if(path.size() % 2 == 0) {
            if(N < blackCount * 2) {
                System.out.println("Fennec");
            }
            else{
                System.out.println("Snuke");
            }
        }
        else {
            if(N < blackCount * 2 + 1) {
                System.out.println("Fennec");
            }
            else{
                System.out.println("Snuke");
            }
        }
    }

    static List<Integer> dijkstra(List<List<Integer>> tree, int N) {
        LinkedList<List<Integer>> stack = new LinkedList<>();
        stack.add(Collections.singletonList(1));
        List<List<Integer>> ret = new ArrayList<>();
        for (int i :IntStream.range(0, N).toArray()){
            List<Integer> current = stack.removeFirst();
            int node = current.get(current.size()-1);
            tree.stream().filter(x -> x.contains(node)).forEach(path ->{
                int next = path.get(0) != node ? path.get(0) : path.get(1);
                if(next == N) {
                    List<Integer> tmp = new ArrayList<>(current);
                    tmp.add(next);
                    ret.add(tmp);
                }
                if(!current.contains(next)) {
                    List<Integer> tmp = new ArrayList<>(current);
                    tmp.add(next);
                    stack.add(tmp);
                }
            });
            if(!ret.isEmpty()) {
                return ret.get(0);
            }
        }
        return null;
    }

    static int count(List<List<Integer>> tree, List<Integer> black, int forbidden, int N) {
        List<Integer> tmp = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int firstSize = tree.size();
            for(int j = 0; j < tree.size();){
                int a = tree.get(j).get(0);
                int b = tree.get(j).get(1);
                if(a == forbidden || b == forbidden) {
                    tree.remove(j);
                    continue;
                }
                for (int data : black) {
                    if(data == a && !black.contains(b)) {
                        tree.remove(j);
                        tmp.add(b);
                        break;
                    }
                    else if(data == b && !black.contains(a)) {
                        tree.remove(j);
                        tmp.add(a);
                        break;
                    }
                }
                if(tmp.isEmpty()) {
                    j++;
                }
                else {
                    black.addAll(tmp);
                    tmp.clear();
                }
            }
            if(firstSize == tree.size()) {
                return black.size();
            }
        }
        return black.size();
    }
}