Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])


Fixed submission:
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])


Fixed submission:
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
def dfs(i):
    stack = []
    visited[i] = True
    stack.append(i)
    while len(stack) != 0:
        v = stack.pop()
        W = w[v]
        ans[v] += W
        for c in g[v]:
            if not visited[c]:
                visited[c] = True
                stack.append(c)
                ans[c] += ans[v]

dfs(1)
print(*ans[1:])

Fixed submission:
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
def dfs(i):
    stack = []
    visited[i] = True
    stack.append(i)
    while len(stack) != 0:
        v = stack.pop()
        W = w[v]
        ans[v] += W
        for c in g[v]:
            if not visited[c]:
                visited[c] = True
                stack.append(c)
                ans[c] += ans[v]

dfs(1)
print(*ans[1:])

Fixed submission:
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])