Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

def dfs(i, p):
  for c in nodes[i]:
    if c != p:
      values[c] += values[i]
      dfs(c, i)

dfs(0, None)
print(*values)


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

def dfs(i, p):
  for c in nodes[i]:
    if c != p:
      values[c] += values[i]
      dfs(c, i)

dfs(0, None)
print(*values)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

def dfs(i, p):
  for c in nodes[i]:
    if c != p:
      values[c] += values[i]
      dfs(c, i)

dfs(0, None)
print(*values)


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

def dfs(i, p):
  for c in nodes[i]:
    if c != p:
      values[c] += values[i]
      dfs(c, i)

dfs(0, None)
print(*values)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

marked = []
def dfs(i):
  marked.append(i)
  for c in nodes[i]:
    if c not in marked:
      values[c] += values[i]
      dfs(c)

dfs(0)
print(*values)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

def dfs(i, p):
  for c in nodes[i]:
    if c != p:
      values[c] += values[i]
      dfs(c, i)

dfs(0, None)
print(*values)

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
    def __init__(self, id):
        self.id = id
        self.value = 0
        self.children = []
    
    def spread(self):
        if len(self.children)==0:
            return
        
        for child in self.children:
            child.value += self.value
            child.spread()
        

n, q = map(int, input().split())

edges = [tuple(map(int, input().split())) for _ in range(n-1)]
nodedict = dict()
root = Node(1)
nodedict[root.id] = root

marked = [root.id]
while len(edges) > 0:
    tmp = []
    rm = []
    for i, edge in enumerate(edges):
        if edge[0] in marked:
            new = Node(edge[1])
            nodedict[edge[1]] = new
            nodedict[edge[0]].children.append(new)
            rm.append(edge)
            tmp.append(edge[1])
        elif edge[1] in marked:
            new = Node(edge[0])
            nodedict[edge[0]] = new
            nodedict[edge[1]].children.append(new)
            rm.append(edge)
            tmp.append(edge[0])
    marked = tmp
    for r in rm:
      edges.remove(r)

for _ in range(q):
    p, x = map(int, input().split())
    nodedict[p].value += x

root.spread()

print(' '.join([str(nodedict[i].value) for i in range(1, n+1)]))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())

nodes = [[] for _ in range(N)]
values = [0 for _ in range(N)]

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

for _ in range(Q):
  p, x = map(int, input().split())
  p = p-1
  values[p] += x

def dfs(i, p):
  for c in nodes[i]:
    if c != p:
      values[c] += values[i]
      dfs(c, i)

dfs(0, None)
print(*values)