Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

l = [[] for i in range(n)]
for a, b in ab:
    a, b = a - 1, b - 1
    l[a].append(b)
    l[b].append(a)

value = [0 for i in range(n)]
for p, x in px:
    value[p] += x

s = [0]
flag = [False]*(n)
while s:
    v = s.pop()
    flag[v] = True
    for e in l[v]:
        if flag[e]:
            continue
        value[e] += value[v]
        s.append(e)

print(*value)


Fixed submission:
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

l = [[] for i in range(n+1)]
for a, b in ab:
    l[a].append(b)
    l[b].append(a)

value = [0 for i in range(n+1)]
for p, x in px:
    value[p] += x

s = [1]
flag = [False]*(n+1)
while s:
    v = s.pop()
    flag[v] = True
    for e in l[v]:
        if flag[e]:
            continue
        value[e] += value[v]
        s.append(e)

print(*value[1:])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)


def dfs(i, j=-1):
    global g
    for k in g[i]:
        if k == j:
            continue

        ans[k] += ans[i]
        dfs(k, i)


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

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

ans = [0]*n
for j in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0)
print(*ans)


Fixed submission:
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

l = [[] for i in range(n+1)]
for a, b in ab:
    l[a].append(b)
    l[b].append(a)

value = [0 for i in range(n+1)]
for p, x in px:
    value[p] += x

s = [1]
flag = [False]*(n+1)
while s:
    v = s.pop()
    flag[v] = True
    for e in l[v]:
        if flag[e]:
            continue
        value[e] += value[v]
        s.append(e)

print(*value[1:])

Buggy python submission (verdict: Runtime Error):
    import sys
    sys.setrecursionlimit(10**6)
     
    n, q = map(int, input().split())
    g = [[] for _ in range(n)]
    for i in range(n-1):
      a, b = map(int, input().split())
      a, b = a-1, b-1
      g[a].append(b)
      #g[b].append(a)
     
    ans = [0]*n  
    for j in range(q):
      p, x = map(int, input().split())
      ans[p-1] += x
      
    from collections import deque
    s = deque()
    s.append(0)
     
    while s:
      v = s.pop()
      for v_ in g[v]:
        ans[v_] += ans[v]
        s.append(v_)
     
    print(' '.join(map(str, ans)))

Fixed submission:
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

l = [[] for i in range(n+1)]
for a, b in ab:
    l[a].append(b)
    l[b].append(a)

value = [0 for i in range(n+1)]
for p, x in px:
    value[p] += x

s = [1]
flag = [False]*(n+1)
while s:
    v = s.pop()
    flag[v] = True
    for e in l[v]:
        if flag[e]:
            continue
        value[e] += value[v]
        s.append(e)

print(*value[1:])