Buggy python submission (verdict: Runtime Error):
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while len(wait_q) > 0:
    parent = wait_q.popleft()
    already[child] = True
    for child in graph[parent]:
        if child == 0:continue
        if already[child] == True:continue
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)


Fixed submission:
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while len(wait_q) > 0:
    parent = wait_q.popleft()
    for child in graph[parent]:
        if child == 0:continue
        if already[child] == True:continue
        already[child] = True
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x

def bfs(parent,current):
    if not graph[parent]:
        return
    if not (parent == 0 and current == 0):
        cnt[current] += cnt[parent]

    for child in graph[current]:
        bfs(current,child)

bfs(0,0)
print(*cnt)



Fixed submission:
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while len(wait_q) > 0:
    parent = wait_q.popleft()
    for child in graph[parent]:
        if child == 0:continue
        if already[child] == True:continue
        already[child] = True
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)

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

n,q = map(int,input().split())
costs = [0]*n
net = [[] for _ in range(n)]
for _ in range(1,n):
	a,b = map(int,input().split())	
	a -= 1
	b -= 1
	net[a].append(b)
	net[b].append(a)
	
for _ in range (q):
	p,x = map(int,input().split())
	p -= 1
	costs[p] += x

def dfs(parents,checked_par):
	for children in net[parents]:
		if children == checked_par:
			continue
		costs[children] += costs[parents]
		dfs(children,parents)
dfs(0,-1)

print(*costs)


Fixed submission:
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while len(wait_q) > 0:
    parent = wait_q.popleft()
    for child in graph[parent]:
        if child == 0:continue
        if already[child] == True:continue
        already[child] = True
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)

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

n,q = map(int,input().split())
costs = [0]*n
net = [[] for _ in range(n)]
for _ in range(1,n):
	a,b = map(int,input().split())	
	a -= 1
	b -= 1
	net[a].append(b)
	net[b].append(a)
	
for _ in range (q):
	p,x = map(int,input().split())
	costs[p-1] += x

def dfs(parents,checked_par):
	for children in net[parents]:
		if children == checked_par:
			continue
		costs[children] += costs[parents]
		dfs(children,parents)
dfs(0,-1)

print(*costs)


Fixed submission:
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while len(wait_q) > 0:
    parent = wait_q.popleft()
    for child in graph[parent]:
        if child == 0:continue
        if already[child] == True:continue
        already[child] = True
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)