Problem p02936 (python)

Fixed submission:
tmp = list(map(int, (input().split())))
n = tmp[0]
q = tmp[1]

#edge = defaultdict(list)
edge = [[] for i in range(n+1)]
fixed = [False] * (n + 1)
fixed[1] = True
point = [0] * (n + 1)

for i in range(1, n):
  tmp = list(map(int, (input().split())))
  edge[tmp[0]].append(tmp[1])
  edge[tmp[1]].append(tmp[0])

for i in range(1, q+1):
  tmp = list(map(int, (input().split())))
  point[tmp[0]] += tmp[1]

que = []
que += edge[1]
frm = 1

while len(que) != 0:
  cur = que.pop()
  for i in edge[cur]:
    if fixed[i]:
      point[cur] += point[i]
    else:
      que.append(i)
  fixed[cur] = True

for i in range(1, n+1):
  print (point[i], end=" ")

Buggy submission (verdict: Runtime Error):
    import sys
    sys.setrecursionlimit(10**8)
        
    def treetrace(i):
      score = [-1] * (n + 1)
      if src[i] == 0:
        return point[i]
      elif score[i] != -1:
        return score[i]
      else:
        score[i] = point[i] + treetrace(src[i])
        return score[i]
      
    tmp = list(map(int, (input().split())))
    n = tmp[0]
    q = tmp[1]
     
    src = [0] * (n + 1)
    for i in range(1, n):
      tmp = list(map(int, (input().split())))
      src[tmp[1]] = tmp[0]
     
    point = [0] * (n + 1)
    for i in range(1, q+1):
      tmp = list(map(int, (input().split())))
      point[tmp[0]] += tmp[1]
      
    for i in range(1, n + 1):
      print(treetrace(i), end=" ")

Buggy submission (verdict: Runtime Error):
    import sys
    sys.setrecursionlimit(10**8)
     
    def treetrace(i):
      score = [-1] * (n + 1)
      if src[i] == 0:
        return point[i]
      elif score[i] != -1:
        return score[i]
      else:
        score[i] = point[i] + treetrace(src[i])
        return score[i]
      
    tmp = list(map(int, (input().split())))
    n = tmp[0]
    q = tmp[1]
     
    src = [0] * (n + 1)
    for i in range(1, n):
      tmp = list(map(int, (input().split())))
      src[tmp[1]] = tmp[0]
     
    point = [0] * (n + 1)
    for i in range(1, q+1):
      tmp = list(map(int, (input().split())))
      point[tmp[0]] += tmp[1]
      
    for i in range(1, n + 1):
      print(treetrace(i), end=" ")

Buggy submission (verdict: Runtime Error):
    import sys
    sys.setrecursionlimit(10**8)
     
    def treetrace(i):
      score = [-1] * (n + 1)
      if src[i] == 0:
        return point[i]
      elif score[i] != 0:
        return score[i]
      else:
        score[i] = point[i] + treetrace(src[i])
        return score[i]
      
    tmp = list(map(int, (input().split())))
    n = tmp[0]
    q = tmp[1]
     
    src = [0] * (n + 1)
    for i in range(1, n):
      tmp = list(map(int, (input().split())))
      src[tmp[1]] = tmp[0]
     
    point = [0] * (n + 1)
    for i in range(1, q+1):
      tmp = list(map(int, (input().split())))
      point[tmp[0]] += tmp[1]
      
    for i in range(1, n + 1):
      print(treetrace(i), end=" ")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

def treetrace(i):
  score = [0] * (n + 1)
  if src[i] == 0:
    return point[i]
  elif score[i] != 0:
    return score[i]
  else:
    return score[i] = point[i] + treetrace(src[i])
  
tmp = list(map(int, (input().split())))
n = tmp[0]
q = tmp[1]

src = [0] * (n + 1)
for i in range(1, n):
  tmp = list(map(int, (input().split())))
  src[tmp[1]] = tmp[0]

point = [0] * (n + 1)
for i in range(1, q+1):
  tmp = list(map(int, (input().split())))
  point[tmp[0]] += tmp[1]
  
for i in range(1, n + 1):
  print(treetrace(i), end=" ")