Problem p03660 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

def main():
  n = int(input())
  F = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a].append(b)
    F[b].append(a)
  seenB = [False]*n
  seenW = [False]*n
  distB = [0]*n
  distW = [0]*n
  def dfs(v, seen, dist):
    seen[v] = True
    for nv in F[v]:
      if seen[nv]:
        continue
      dist[nv] = dist[v] + 1
      dfs(nv, seen, dist)
  dfs(0, seenB, distB)
  dfs(n-1, seenW, distW)
  b, w = 0, 0
  for i in range(n):
    if distB[i] <= distW[i]:
      b += 1
    else:
      w += 1
  if b > w:
    print("Fennec")
  else:
    print("Snuke")
      
if __name__ == '__main__':
  main()

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

def main():
  n = int(input())
  F = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a].append(b)
    F[b].append(a)
  seenB = [False]*n
  seenW = [False]*n
  seenB[n-1] = True
  seenW[0] = True
  def dfs(v, seen):
    seen[v] = True
    for nv in F[v]:
      if seen[nv]:
        continue
      dfs(nv, seen)
  dfs(0, seenB)
  dfs(n-1, seenW)
  print(seenB, seenW)
  aplusc = seenB.count(True) - 2
  bplusc = seenW.count(True) - 2
  print(aplusc, bplusc)
  c = aplusc + bplusc + 2 - n
  a = aplusc - c
  b = bplusc - c
  print(a, b, c)
  if c%2 == 0:
    if a > b:
      print("Fennec")
    else:
      print("Snuke")
  else:
    if a >= b:
      print("Fennec")
    else:
      print("Snuke")
      
if __name__ == '__main__':
  main()

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

def main():
  n = int(input())
  F = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a].append(b)
    F[b].append(a)
  seenB = [False]*n
  seenW = [False]*n
  seenB[n-1] = True
  seenW[0] = True
  def dfs(v, seen):
    seen[v] = True
    rep = 1
    for nv in F[v]:
      if seen[nv]:
        continue
      rep += dfs(nv, seen)
    return rep
  aplusc = dfs(0, seenB) - 1
  bplusc = dfs(n-1, seenW) - 1
  print(aplusc, bplusc)
  c = aplusc + bplusc + 2 - n
  a = aplusc - c
  b = bplusc - c
  if c%2 == 0:
    if a > b:
      print("Fennec")
    else:
      print("Snuke")
  else:
    if a >= b:
      print("Fennec")
    else:
      print("Snuke")
      
if __name__ == '__main__':
  main()

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

def main():
  n = int(input())
  F = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a].append(b)
    F[b].append(a)
  seenB = [False]*n
  seenW = [False]*n
  seenB[n-1] = True
  seenW[0] = True
  def dfs(v, seen):
    seen[v] = True
    rep = 1
    for nv in F[v]:
      if seen[nv]:
        continue
      rep += dfs(nv, seen)
    return rep
  aplusc = dfs(0, seenB)
  bplusc = dfs(n-1, seenW)
  c = aplusc + bplusc + 2 - n
  a = aplusc - c
  b = bplusc - c
  if c%2 == 0:
    if a > b:
      print("Fennec")
    else:
      print("Snuke")
  else:
    if a >= b:
      print("Fennec")
    else:
      print("Snuke")
      
if __name__ == '__main__':
  main()