Problem: 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.

Submission attempts (in order):
    
    
    
    #                EF-|   |-GH...
    
    
    
    
    
    n = int(input())
    INF = 10**6
    graph = [[float("inf")]*n for i in range(n)]
    for i in range(n - 1):
        a, b = map(int, input().split())
        graph[a - 1][b -1] = 1
        graph[b - 1][a - 1] = 1
     
    
     
     
    import heapq
     
    class Dijkstra(object):
        def dijkstra(self, adj, start, goal=None):
            
            num = len(adj)          
            dist = [float('inf') for i in range(num)] 
            prev = [float('inf') for i in range(num)] 
            
            dist[start] = 0
            q = []                  
            heapq.heappush(q, (0, start)) 
     
            while len(q) != 0:
                prov_cost, src = heapq.heappop(q) # pop
                
                
                if dist[src] < prov_cost:
                    continue
     
                
                for dest in range(num):
                    cost = adj[src][dest]
                    if cost != float('inf') and dist[dest] > dist[src] + cost:
                        dist[dest] = dist[src] + cost 
                        heapq.heappush(q, (dist[dest], dest)) 
                        prev[dest] = src                      
                        
            if goal is not None:
                return self.get_path(goal, prev)
            else:
                return dist
     
        def get_path(self, goal, prev):
            
            path = [goal]           
            dest = goal
     
            
            while prev[dest] != float('inf'):
                path.append(prev[dest])
                dest = prev[dest]
     
            
            return list(reversed(path))
    d = Dijkstra()
    
    
    cnt = 0
    for i, j in zip(d.dijkstra(graph, start=0,), d.dijkstra(graph, start=n-1)):
        if i <= j:
            cnt += 1
    print("Fennec" if cnt > n//2 else "Snuke")
    

from collections import deque
n = int(input())
board = [0]*n
edge = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
q = deque()
q.append((0,1))
q.append((-1,-1))
while q:
    from_, color = q.popleft()
    if board[from_] != 0:
        continue
    board[from_] = color
    for i in edge[from_]:
        q.append((i,color))
if sum(board) > 0:
    print("Fennec")
else:
    print("Snuke")

Verdicts: Runtime Error

Accepted