Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)
n,q = map(int,input().split())
g = [[] for _ in range(n)]
p = [0]*n
for _ in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
for _ in range(q):
    a,b = map(int,input().split())
    a -= 1
    p[a] += b

def dfs(now, prev=-1):
    for nx in g[now]:
        if nx==prev:
            continue
        p[nx] += p[now]
        dfs(nx, now)
dfs(0)
print(*p)

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    values = [0]*n
    links = [[] for _ in range(n)]
    for _ in range(n-1):
        a,b = map(int,input().split())
        links[a-1].append(b-1)
        links[b-1].append(a-1)
    
    for _ in range(q):
        p,x = map(int,input().split())
        values[p-1] += x
    d = deque()
    d.append((0,-1))
    
    while len(d) != 0:
        i,p = d.popleft()
        for j in links[i]:
            if j==p:
                continue
            values[j] += values[i]
            d.append((j,i))
    print(*values)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n,q = map(int,input().split())
graph = [[] for i 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)

for i in range(q):
    p,x = map(int,input().split())
    p -= 1
    cnt[p] += x
    que = deque(graph[p])
    while que:
        c = que.popleft()
        cnt[c] += x
        que += deque(graph[c])       

print(str(cnt).replace('[','').replace(']','').replace(',',''))


Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    values = [0]*n
    links = [[] for _ in range(n)]
    for _ in range(n-1):
        a,b = map(int,input().split())
        links[a-1].append(b-1)
        links[b-1].append(a-1)
    
    for _ in range(q):
        p,x = map(int,input().split())
        values[p-1] += x
    d = deque()
    d.append((0,-1))
    
    while len(d) != 0:
        i,p = d.popleft()
        for j in links[i]:
            if j==p:
                continue
            values[j] += values[i]
            d.append((j,i))
    print(*values)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n,q = map(int,input().split())
graph = [[] for i 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)

for i in range(q):
    p,x = map(int,input().split())
    p -= 1
    cnt[p] += x
    que = deque(graph[p])
    while que:
        c = que.popleft()
        cnt[c] += x
        que += deque(graph[c])       

print(str(cnt).replace('[','').replace(']','').replace(',',''))


Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    values = [0]*n
    links = [[] for _ in range(n)]
    for _ in range(n-1):
        a,b = map(int,input().split())
        links[a-1].append(b-1)
        links[b-1].append(a-1)
    
    for _ in range(q):
        p,x = map(int,input().split())
        values[p-1] += x
    d = deque()
    d.append((0,-1))
    
    while len(d) != 0:
        i,p = d.popleft()
        for j in links[i]:
            if j==p:
                continue
            values[j] += values[i]
            d.append((j,i))
    print(*values)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n,q = map(int,input().split())
graph = [[] for _ in range(n)]
connect = [[_] 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(n):
    que = deque(graph[i])
    while que:
        c = que.popleft()
        if c > i:
            connect[i].append(c)
            for j in graph[c]:
                if j > i and j not in connect[i]:
                    que.append(j)

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

print(str(cnt).replace('[','').replace(']','').replace(',',''))


Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    values = [0]*n
    links = [[] for _ in range(n)]
    for _ in range(n-1):
        a,b = map(int,input().split())
        links[a-1].append(b-1)
        links[b-1].append(a-1)
    
    for _ in range(q):
        p,x = map(int,input().split())
        values[p-1] += x
    d = deque()
    d.append((0,-1))
    
    while len(d) != 0:
        i,p = d.popleft()
        for j in links[i]:
            if j==p:
                continue
            values[j] += values[i]
            d.append((j,i))
    print(*values)
    
main()