Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
from collections import deque

n = int(input())

edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

nodes = [0 for _ in range(n)]
"""
white = all - black
"""

goal = n - 1
def dfs(num, f_num):
    if num == goal:
        nodes[num] = 1
        return 1
    s = 0
    for node in edges[num]:
        if node == f_num:
            continue
        s += dfs(node, num)
    nodes[num] = s + 1
    return s + 1

def dist(start, end):
    q =  deque([(0, -1, 1)])
    res = 0
    while len(q) > 0:
        num, f_num, dist = q.popleft()
        if num == end:
            res = dist
        for node in edges[num]:
            if node == f_num:
                continue
            q.append((node, num, dist + 1))
    return res

dfs(0, -1)
fennec = nodes[0] - dist(0, n-1) // 2
snuke = n - fennec
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")


Fixed submission:
import sys
input = sys.stdin.buffer.readline
from collections import deque

n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

def get_dists(f):
    dists = [0 for _ in range(n)]
    q = deque()
    q.append((f, -1, 0))
    while len(q) > 0:
        num, f_num, dist = q.popleft()
        for node in edges[num]:
            if node == f_num:
                continue
            else:
                dists[node] = dist + 1
                q.append((node, num, dist+1))
    return dists

dist_1 = get_dists(0)
dist_n = get_dists(n-1)

ans = 0
for i in range(n):
    if dist_1[i] <= dist_n[i]:
        ans += 1

fennec = ans
snuke = n - fennec
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

n = int(input())

edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

nodes = [0 for _ in range(n)]
"""
white = all - black
"""

goal = n - 1
def dfs(num, f_num):
    if num == goal:
        nodes[num] = 1
        return 1
    s = 0
    for node in edges[num]:
        if node == f_num:
            continue
        s += dfs(node, num)
    nodes[num] = s + 1
    return s + 1

def dist(start, end):
    q = [(0, -1, 1)]
    res = 0
    while len(q) > 0:
        num, f_num, dist = q.pop()
        print(num, f_num, dist)
        if num == end:
            res = dist
        for node in edges[num]:
            if node == f_num:
                continue
            q.append((node, num, dist + 1))
    return res

dfs(0, -1)
fennec = nodes[0] - dist(0, n-1) // 2
snuke = n - fennec
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")


Fixed submission:
import sys
input = sys.stdin.buffer.readline
from collections import deque

n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

def get_dists(f):
    dists = [0 for _ in range(n)]
    q = deque()
    q.append((f, -1, 0))
    while len(q) > 0:
        num, f_num, dist = q.popleft()
        for node in edges[num]:
            if node == f_num:
                continue
            else:
                dists[node] = dist + 1
                q.append((node, num, dist+1))
    return dists

dist_1 = get_dists(0)
dist_n = get_dists(n-1)

ans = 0
for i in range(n):
    if dist_1[i] <= dist_n[i]:
        ans += 1

fennec = ans
snuke = n - fennec
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")