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 Scala (2.11.7) (judge verdict: Wrong Answer)

import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val e = Array.ofDim[mutable.Set[Int]](N + 1)
    (0 until N - 1) foreach { _ =>
      val u = sc.nextInt()
      val v = sc.nextInt()
      if (e(u) == null) e(u) = mutable.Set.empty
      if (e(v) == null) e(v) = mutable.Set.empty
      e(u) += v
      e(v) += u
    }

    def findPath(s: Int, t: Int): Seq[Int] = {
      val INF = N + 10
      val d = Array.fill(N + 1)(INF)
      val q = mutable.PriorityQueue.empty[(Int, Int)](Ordering.by((_: (Int, Int))._1)) // (cost, 頂点)
      val prev = Array.fill(N + 1)(-1)

      d(s) = 0
      q.enqueue((0, s))

      while(q.nonEmpty) {
        val (cost, v) = q.dequeue()
        if (cost <= d(v)) {
          e(v).foreach { u =>
            if (d(u) > d(v) + 1) {
              d(u) = d(v) + 1
              prev(u) = v
              q.enqueue((d(u), u))
            }
          }
        }
      }

      def traceback(v: Int, end: Int, path: List[Int]): List[Int] = v match {
        case `end` => v :: path
        case _ => traceback(prev(v), end, v :: path)
      }

      traceback(t, s, Nil)
    }

    def delEdge(u: Int, v: Int): Unit = {
      e(u) -= v
      e(v) -= u
    }

    val oneToN = findPath(1, N)
    oneToN zip oneToN.drop(1) foreach {
      case (u, v) => delEdge(u, v)
    }

    val uf = new UnionFind(N + 1)
    e.indices foreach { v =>
      if (e(v) != null )
        e(v).foreach { u =>
          uf.unite(v, u)
        }
    }

    def countConnected(v: Int): Int = {
      val r = uf.find(v)
      ((1 to N) count (v => uf.find(v) == r)) - 1
    }

    val c1 = countConnected(1)
    val cN = countConnected(N)

    val len = oneToN.length - 2
    val winner = if (c1 + (len & 1) > cN) "Fennec"
    else "Snuke"

    println(winner)
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextChar(): Char = next.charAt(0)
  }

  class UnionFind(n: Int) {
    private val par = Array.iterate(0, n)(_ + 1)
    private val rank = Array.ofDim[Int](n)

    def find(x: Int): Int = {
      if (par(x) == x) x
      else {
        par(x) = find(par(x))
        par(x)
      }
    }

    def unite(x: Int, y: Int): Unit = {
      val x1 = find(x)
      val y1 = find(y)
      if (x1 != y1) {
        if (rank(x1) < rank(y)) {
          par(x1) = y1
        } else {
          par(y1) = x1
          if (rank(x1) == rank(y1)) rank(x1) += 1
        }
      }
    }
  }
}