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

sys.setrecursionlimit(10 ** 9)


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for i in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

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

sys.setrecursionlimit(10 ** 9)


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

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

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*cnt[1:])

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

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

sys.setrecursionlimit(10 ** 9)


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

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

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

dfs(0, -1)

print(*cnt)

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

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

sys.setrecursionlimit(10 ** 9)


def dfs(v, p, c):
    cnt[v] += c
    for next_v in g[v]:
        if next_v == p:
            continue
        dfs(next_v, v, cnt[v])


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

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

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

dfs(0, -1, 0)

print(*cnt)

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

Buggy python submission (verdict: Time Limit Exceeded):

import sys

sys.setrecursionlimit(10 ** 6)


def dfs(v, p, c):
    cnt[v]+=c
    for next_v in g[v]:
        if next_v == p:
            continue
        dfs(next_v, v, cnt[v])

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

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

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


dfs(0, -1, 0)

print(*cnt)

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

Buggy python submission (verdict: Runtime Error):
n,q=list(map(int,input().split()))

ab=[[] for _ in range(n)]
arr=[0 for _ in range(n)]
cache=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  ab[a-1].append(b-1)

px=[list(map(int,input().split())) for _ in range(q)]
  
  
def search(tree, root):
  arr=[]
  children=tree[root]
  if children == []:
    return None
  else:
    arr.extend(children)
    for child in children:
      ret=search(tree, child)
      if ret is not None:
        arr.extend(ret)    
  return arr


for p,x in px:
  if cache[p-1] == []:
    children=search(ab,p-1)
    if children is not None:
      children=[p-1]+children
    else:
      children=[p-1]
    cache[p-1]=children
    for child in children:
      arr[child]+=x
  else:
    for child in cache[p-1]:
      arr[child]+=x    
print(*arr)
    

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

Buggy python submission (verdict: Runtime Error):
n,q=list(map(int,input().split()))

ab=[[] for _ in range(n)]
arr=[0 for _ in range(n)]

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

px=[list(map(int,input().split())) for _ in range(q)]
  
  
def search(tree, root):
  arr=[]
  children=tree[root]
  if children == []:
    return None
  else:
    arr.extend(children)
    for child in children:
      ret=search(tree, child)
      if ret is not None:
        arr.extend(ret)    
  return arr
      
for p,x in px:
  children=search(ab,p-1)
  if children is not None:
    children=[p-1]+children
  else:
    children=[p-1]
  for child in children:
    arr[child]+=x
print(*arr)
    

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


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])