Buggy python submission (verdict: Time Limit Exceeded):
# import sys
from collections import deque
# sys.setrecursionlimit(10 ** 5)

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

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

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

done = [True for _ in range(N)]
stack = deque([])
done[0] = False
for e in edge[0]:
    stack.append([e, 0])
while stack:
    s = stack.pop()
    if done[s[0]]:
        done[s[0]] = False
        counter[s[0]] += counter[s[1]]
        for n in edge[s[0]]:
            stack.append([n, s[0]])

[print(c, end=" ") for c in counter]

Fixed submission:
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

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

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

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]

Buggy python submission (verdict: Time Limit Exceeded):
# import sys
from collections import deque
# sys.setrecursionlimit(10 ** 5)

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

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

def dfs():
    global counter
    done = [True for _ in range(N)]
    stack = deque([])
    done[0] = False
    for e in edge[0]:
        stack.append([e, 0])
    while stack:
        s = stack.pop()
        if done[s[0]]:
            done[s[0]] = False
            counter[s[0]] += counter[s[1]]
            for n in edge[s[0]]:
                stack.append([n, s[0]])
                
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x
dfs()

[print(c, end=" ") for c in counter]

Fixed submission:
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

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

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

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

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

def dfs():
    global counter
    done = [True for _ in range(N)]
    stack = deque([])
    done[0] = False
    for e in edge[0]:
        stack.append([e, 0])
    while stack:
        s = stack.pop()
        if done[s[0]]:
            done[s[0]] = False
            counter[s[0]] += counter[s[1]]
            for n in edge[s[0]]:
                stack.append([n, s[0]])
                
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x
dfs()

[print(c, end=" ") for c in counter]

Fixed submission:
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

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

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

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]

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

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

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

def dfs():
    global counter
    done = [True for _ in range(N)]
    stack = deque([])
    done[0] = False
    for e in edge[0]:
        stack.append([e, 0])
    while stack:
        s = stack.pop()
        if done[s[0]]:
            done[s[0]] = False
            counter[s[0]] += counter[s[1]]
            for n in edge[s[0]]:
                stack.append([n, s[0]])
                
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x
dfs()

[print(c, end=" ") for c in counter]

Fixed submission:
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

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

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

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]

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

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

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

def dfs(p, x):
    global counter
    flag = False
    done = [True for _ in range(N)]
    done[0] = False
    if p == 0:
        counter[0] += x
        flag = True
    stack = deque(edge[0])
    while stack:
        s = stack.popleft()
        if done[s]:
            if s == p:
                flag = True
                while stack:
                    stack.pop()
            if flag:
                counter[s] += x
            done[s] = False
            for n in edge[s]:
                stack.append(n)
                
for _ in range(Q):
    p, x = map(int, input().split())
    dfs(p - 1, x)

[print(c, end=" ") for c in counter]  

Fixed submission:
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

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

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

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]

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

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

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

def dfs(p, x):
    global counter
    flag = False
    done = [True for _ in range(N)]
    done[0] = False
    if p == 0:
        counter[0] += x
        flag = True
    stack = deque(edge[0])
    while stack:
        s = stack.pop()
        if done[s]:
            if s == p:
                flag = True
                while stack:
                    stack.pop()
            if flag:
                counter[s] += x
            done[s] = False
            for n in edge[s]:
                stack.append(n)
                
for _ in range(Q):
    p, x = map(int, input().split())
    dfs(p - 1, x)

[print(c, end=" ") for c in counter]

Fixed submission:
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

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

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

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]