Buggy python submission (verdict: Time Limit Exceeded):
# D - Ki

import queue

N, Q = map(int, input().split())

children = [[] for _ in range(N)]
points = [0] * N

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

for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x

q = queue.Queue()
q.put(0)
visited = [False] * N
while not q.empty():
    key = q.get()
    for child in children[key]:
        if visited[child] == True:
            continue
        points[child] += points[key]
        visited[key] = True
        q.put(child)

print(*points)


Fixed submission:
# D - Ki

N, Q = map(int, input().split())

children = [[] for _ in range(N)]
points = [0] * N

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

for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x

stack = []
stack.append(0)
visited = [False] * N
while stack:
    key = stack.pop()
    for child in children[key]:
        if visited[child] == True:
            continue
        points[child] += points[key]
        visited[key] = True
        stack.append(child)

print(*points)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Ki

import queue

N, Q = map(int, input().split())
children = [[] for _ in range(N)]
points = [0 for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    children[a - 1].append(b - 1)
    children[b - 1].append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x

q = queue.Queue()
q.put(0)
visited = [False] * N
while not q.empty():
    key = q.get()
    visited[key] = True
    for child in children[key]:
        if visited[child] == False:
            points[child] += points[key]
            q.put(child)

print(*points)


Fixed submission:
# D - Ki

N, Q = map(int, input().split())

children = [[] for _ in range(N)]
points = [0] * N

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

for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x

stack = []
stack.append(0)
visited = [False] * N
while stack:
    key = stack.pop()
    for child in children[key]:
        if visited[child] == True:
            continue
        points[child] += points[key]
        visited[key] = True
        stack.append(child)

print(*points)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Ki

import queue

class Node:
    def __init__(self, children, point):
        self.children = children
        self.point = 0

N, Q = map(int, input().split())
nodes = [Node([], 0) for i in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    nodes[a - 1].children.append(b - 1)
    nodes[b - 1].children.append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    nodes[p - 1].point += x

q = queue.Queue()
q.put(0)
visited = [False] * N
while not q.empty():
    key = q.get()
    visited[key] = True
    for child in nodes[key].children:
        if visited[child] == False:
            nodes[child].point += nodes[key].point
            q.put(child)

print(*[node.point for node in nodes])


Fixed submission:
# D - Ki

N, Q = map(int, input().split())

children = [[] for _ in range(N)]
points = [0] * N

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

for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x

stack = []
stack.append(0)
visited = [False] * N
while stack:
    key = stack.pop()
    for child in children[key]:
        if visited[child] == True:
            continue
        points[child] += points[key]
        visited[key] = True
        stack.append(child)

print(*points)