Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, Q = map(int, input().split())

    values = [0] * N
    links = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop(0)
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))
    print(*values)

main()

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())

values = [0] * N
links = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)
for _ in range(Q):
    p, x = map(int, input().split())
    values[p - 1] += x

s = [(0, -1)]
while s:
    i, p = s.pop(0)
    for j in links[i]:
        if j == p:
            continue
        values[j] += values[i]
        s.append((j, i))
print(*values)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
def main():
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    if childrens[i] is None:
      return
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = map(int, input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [None] * (n + 1)
  dc = [None for i in range(0, n + 1)]
  for i in range(n - 1):
    a, b = map(int, input().split())
    if childrens[a] is None:
      childrens[a] = []
    childrens[a].append(b)
  for _ in range(q):
    p, x = map(int, input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()



Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
def calc_results(results, pvalue, i):
  results[i] = pvalue + values[i]
  if childrens[i] is None:
    return
  for j in childrens[i]:
    calc_results(results, results[i], j)
n, q = map(int, input().split())
values = [0] * (n + 1)
results = [0] * (n + 1)
childrens = [None] * (n + 1)
dc = [None for i in range(0, n + 1)]
for i in range(n - 1):
  a, b = map(int, input().split())
  if childrens[a] is None:
    childrens[a] = []
  childrens[a].append(b)
for _ in range(q):
  p, x = map(int, input().split())
  values[p] += x
calc_results(results, 0, 1)
print(*[results[i] for i in range(1, n + 1)])



Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
def get_descendants(childrens, dc, i):
  if dc[i] is not None:
    return dc[i]
  if childrens[i] is None:
    return []
  dc[i] = []
  dc[i].extend(childrens[i])
  for j in childrens[i]:
    dc[i].extend(get_descendants(childrens, dc, j))
  return dc[i]
n, q = map(int, input().split())
values = [0] * (n + 1)
childrens = [None] * (n + 1)
dc = [None for i in range(0, n + 1)]
for i in range(n - 1):
  a, b = map(int, input().split())
  if childrens[a] is None:
    childrens[a] = []
  childrens[a].append(b)
for _ in range(q):
  p, x = map(int, input().split())
  values[p] += x
  for d in get_descendants(childrens, dc, p):
    values[d] += x
print(*[values[i] for i in range(1, n + 1)])


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
class Node:
  def __init__(self, n):
    self.number = n
    self.children = []
    self.value = 0
def get_descendants(nodes, dc, i):
  if dc[i] is not None:
    return dc[i]
  dc[i] = []
  dc[i].extend(nodes[i].children)
  for j in nodes[i].children:
    dc[i].extend(get_descendants(nodes, dc, j))
  return dc[i]
n, q = map(int, input().split())
nodes = [Node(i) for i in range(0, n + 1)]
nodes[0] = None
dc = [None for i in range(0, n + 1)]
for i in range(n - 1):
  a, b = map(int, input().split())
  nodes[a].children.append(b)
for _ in range(q):
  p, x = map(int, input().split())
  nodes[p].value += x
  for d in get_descendants(nodes, dc, p):
    nodes[d].value += x
print(' '.join(str(nodes[i].value) for i in range(1, n + 1)))


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
class Node:
  def __init__(self, n):
    self.number = n
    self.children = []
    self.value = 0
def add_values(nodes, i, x):
  n = nodes[i]
  n.value += x
  for c in n.children:
    add_values(nodes, c, x)
n, q = map(int, input().split())
nodes = [Node(i) for i in range(0, n + 1)]
nodes[0] = None
for i in range(n - 1):
  a, b = map(int, input().split())
  nodes[a].children.append(b)
for _ in range(q):
  p, x = map(int, input().split())
  add_values(nodes, p, x)
print(' '.join(str(nodes[i].value) for i in range(1, n + 1)))


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy python submission (verdict: Runtime Error):
class Node:
  def __init__(self, n):
    self.number = n
    self.children = []
    self.value = 0
def add_values(nodes, i, x):
  n = nodes[i]
  n.value += x
  for c in n.children:
    add_values(nodes, c, x)
n, q = map(int, input().split())
nodes = [Node(i) for i in range(0, n + 1)]
nodes[0] = None
for i in range(n - 1):
  a, b = map(int, input().split())
  nodes[a].children.append(b)
for _ in range(q):
  p, x = map(int, input().split())
  add_values(nodes, p, x)
print(' '.join(str(nodes[i].value) for i in range(1, n + 1)))


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()