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

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

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

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

check = [0 for _ in range(n)]
def dfs(st) :
  check[st] = 1
  for ne in tree[st] :
    if check[ne] == 1 :
      continue
    ans[ne] += ans[st]
    dfs(ne)

dfs(0)

print(*ans)

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

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

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

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

check = [0 for _ in range(n)]
def dfs(st) :
  check[st] = 1
  for ne in tree[st] :
    if check[ne] == 1 :
      continue
    ans[ne] += ans[st]
    dfs(ne)

dfs(0)

print(*ans)

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

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

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

check = [0 for _ in range(n)]
def dfs(st) :
  check[st] = 1
  for ne in range(n) :
    if tree[st][ne] == 0 :
      continue
    if check[ne] == 1 :
      continue
    ans[ne] += ans[st]
    dfs(ne)

dfs(0)

print(*ans)

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

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

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

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

check = [0 for _ in range(n)]
def dfs(st) :
  check[st] = 1
  for ne in tree[st] :
    if check[ne] == 1 :
      continue
    ans[ne] += ans[st]
    dfs(ne)

dfs(0)

print(*ans)

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

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

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

check = [0 for _ in range(n)]
def dfs(st) :
  check[st] = 1
  for ne in range(n) :
    if tree[st][ne] == 0 :
      continue
    if check[ne] == 1 :
      continue
    ans[ne] += ans[st]
    dfs(ne)

dfs(0)

print(*ans)

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

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

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

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

check = [0 for _ in range(n)]
def dfs(st) :
  check[st] = 1
  for ne in tree[st] :
    if check[ne] == 1 :
      continue
    ans[ne] += ans[st]
    dfs(ne)

dfs(0)

print(*ans)