Buggy python submission (verdict: Runtime Error):
mport sys
from collections import deque

stack = deque()
input = sys.stdin.readline

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

link = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    link[a - 1].append(b)
    #link[b - 1].append(a)
    
states = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    states[p - 1] += x

check = [0] * N
stack.append(1)
check[0] = 1
while stack:
    node = stack.pop()
    for next_node in link[node - 1]:
        if check[next_node - 1]:
            continue
        states[next_node - 1] += states[node - 1]
        check[next_node - 1] = 1
        stack.append(next_node)

# Output
print(*states)


Fixed submission:
import sys
from collections import deque

stack = deque()
input = sys.stdin.readline

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

link = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    link[a - 1].append(b)
    link[b - 1].append(a)
    
states = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    states[p - 1] += x

check = [0] * N
stack.append(1)
check[0] = 1
while stack:
    node = stack.pop()
    for next_node in link[node - 1]:
        if check[next_node - 1]:
            continue
        states[next_node - 1] += states[node - 1]
        check[next_node - 1] = 1
        stack.append(next_node)

# Output
print(*states)

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


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

link = [None] * N 
for _ in range(N-1):
    a, b = map(int, input().split())
    if link[a-1] is None:
        link[a-1] = [b]
    else:
        link[a-1].append(b)

states = [0] * N
stack = deque()


def dfs(x):
    p = stack.popleft()

    # Add score
    states[p-1] += x
    # Search nexts
    nexts = link[p-1]
    if nexts is None:
        return
    for next_node in nexts:
        stack.append(next_node)


def update(p, x):
    stack.append(p)
    while stack:
        dfs(x)


for _ in range(Q):
    p, x = map(int, input().split())
    update(p, x)

# Output
print(' '.join(map(str, states)))


Fixed submission:
import sys
from collections import deque

stack = deque()
input = sys.stdin.readline

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

link = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    link[a - 1].append(b)
    link[b - 1].append(a)
    
states = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    states[p - 1] += x

check = [0] * N
stack.append(1)
check[0] = 1
while stack:
    node = stack.pop()
    for next_node in link[node - 1]:
        if check[next_node - 1]:
            continue
        states[next_node - 1] += states[node - 1]
        check[next_node - 1] = 1
        stack.append(next_node)

# Output
print(*states)

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


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

link = [None] * N 
for _ in range(N-1):
    a, b = map(int, input().split())
    if link[a-1] is None:
        link[a-1] = [b]
    else:
        link[a-1].append(b)

states = [0] * N
stack = deque()


def dfs(x):
    p = stack.popleft()

    # Add score
    states[p-1] += x
    # Search nexts
    nexts = link[p-1]
    if nexts is None:
        return
    for next_node in nexts:
        stack.append(next_node)


def update(p, x):
    stack.append(p)
    while stack:
        dfs(x)


for _ in range(Q):
    p, x = map(int, input().split())
    update(p, x)

# Output
print(' '.join(map(str, states)))


Fixed submission:
import sys
from collections import deque

stack = deque()
input = sys.stdin.readline

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

link = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    link[a - 1].append(b)
    link[b - 1].append(a)
    
states = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    states[p - 1] += x

check = [0] * N
stack.append(1)
check[0] = 1
while stack:
    node = stack.pop()
    for next_node in link[node - 1]:
        if check[next_node - 1]:
            continue
        states[next_node - 1] += states[node - 1]
        check[next_node - 1] = 1
        stack.append(next_node)

# Output
print(*states)