Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
ab = [LIST() for _ in range(N-1)]
px = [LIST() for _ in range(Q)]

tree = defaultdict(list)
for a, b in ab:
	tree[a-1].append(b-1)
	tree[b-1].append(a-1)

dic = defaultdict(int)

for p, x in px:
	dic[p-1] += x

ans = [0]*N

checked = [0]*N
checked[0] = 1

q = deque([])
q.append(0)

while q:
	n = q.popleft()
	ans[n] += dic[n]
	for node in tree[n]:
		if checked[node]:
			continue
		ans[node] += ans[n]
		checked[node] = 1
		q.append(node)

print(*ans)


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
		par[b-1] = a-1

	px = [LIST() for _ in range(Q)]

	ans = [0] * N  # 答え入れる

	for p, x in px:
		ans[p-1] += x

	
	for i in range(1, N):
		ans[i] += ans[par[i]]

	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
	search = []
	searched = [0] * N
	searched[0] = 1
	for child in tree[0]:
		par[child] = 0
		search.append(child)

	while search:
		x = search.pop(0)
		for child in tree[x]:
			if searched[child] == 0:
				par[child] = x
				searched[x] = 1
				search.append(child)

	# def parent(n):
	# 	for child in tree[n]:
	# 		if par[child] == -1:
	# 			par[child] = n
	# 			parent(child)
	# parent(0)
	# print(par)
	px = [LIST() for _ in range(Q)]

	counter = defaultdict(int)  # まとめる
	for p, x in px:
		counter[p-1] += x

	ans = [-1] * N  # 答え入れる
	ans[0] = counter[0]

	search = []
	searched = [0] * N
	searched[0] = 1
	for child in tree[0]:
		par[child] = 0
		search.append(child)

	while search:
		x = search.pop(0)
		ans[x] = counter[x] + ans[par[x]]
		for child in tree[x]:
			if searched[child] == 0:
				par[child] = x
				searched[x] = 1
				search.append(child)

	# def DFS(n):
	# 	if n != 0:
	# 		ans[n] = counter[n] + ans[par[n]]
	# 	for child in tree[n]:
	# 		if ans[child] == -1:
	# 			DFS(child)

	# DFS(0)
	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
		par[b-1] = a-1

	px = [LIST() for _ in range(Q)]

	ans = [0] * N  # 答え入れる

	for p, x in px:
		ans[p-1] += x

	
	for i in range(1, N):
		ans[i] += ans[par[i]]

	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)

	def parent(n):
		for child in tree[n]:
			if par[child] == -1:
				par[child] = n
				parent(child)
	parent(0)
	px = [LIST() for _ in range(Q)]

	counter = defaultdict(int)  # まとめる
	for p, x in px:
		counter[p-1] += x

	ans = [-1] * N  # 答え入れる
	ans[0] = counter[0]

	def DFS(n):
		if n != 0:
			ans[n] = counter[n] + ans[par[n]]
		for child in tree[n]:
			if ans[child] == -1:
				DFS(child)

	DFS(0)
	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
		par[b-1] = a-1

	px = [LIST() for _ in range(Q)]

	ans = [0] * N  # 答え入れる

	for p, x in px:
		ans[p-1] += x

	
	for i in range(1, N):
		ans[i] += ans[par[i]]

	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)

	def parent(n):
		for child in tree[n]:
			if par[child] == -1:
				par[child] = n
				parent(child)
	parent(0)
	px = [LIST() for _ in range(Q)]

	counter = defaultdict(int)  # まとめる
	for p, x in px:
		counter[p-1] += x

	ans = [-1] * N  # 答え入れる
	ans[0] = counter[0]

	def DFS(n):
		if n != 0:
			ans[n] = counter[n] + ans[par[n]]
		for child in tree[n]:
			if ans[child] == -1:
				DFS(child)

	DFS(0)
	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
		par[b-1] = a-1

	px = [LIST() for _ in range(Q)]

	ans = [0] * N  # 答え入れる

	for p, x in px:
		ans[p-1] += x

	
	for i in range(1, N):
		ans[i] += ans[par[i]]

	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def DFS(n):
	if n != 0 and ans[n] != -1:
		return 0
	if not n == 0:
		ans[n] = counter[n] + ans[par[n]]
	for child in tree[n]:
		DFS(child)

N, Q = MAP()
ab = [LIST() for _ in range(N-1)]
tree = defaultdict(list)
for a, b in ab:
	tree[a-1].append(b-1)
	tree[b-1].append(a-1)

par = [-1]*N
par[0] = 0
zyunban = []
for a, b in ab:
	if par[a-1] != -1:  # 親が存在
		par[b-1] = a-1
	elif par[b-1] != -1:
		par[a-1] = b-1
	else:
		par[a-1] = b-1
		par[b-1] = a-1

px = [LIST() for _ in range(Q)]

counter = defaultdict(int)  # まとめる
for p, x in px:
	counter[p-1] += x

ans = [-1] * N  # 答え入れる
ans[0] = counter[0]
DFS(0)
print(*ans, sep=" ")


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
		par[b-1] = a-1

	px = [LIST() for _ in range(Q)]

	ans = [0] * N  # 答え入れる

	for p, x in px:
		ans[p-1] += x

	
	for i in range(1, N):
		ans[i] += ans[par[i]]

	print(*ans, sep=" ")

if  __name__ == "__main__":
	solve()