Buggy python submission (verdict: Runtime Error):
def count(x):
    if len(child_list[x]) > 0:
        for index in child_list[x]:
            total_list[index] += total_list[x]
            count(index)

n, q = map(int, input().split())
child_list = [[] for _ in range(n)]
position_list = [10 * 6] * n
position_list[0] = 1
input_list = []
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a < b:
        a, b = b, a
    input_list.append([b, a])
input_list.sort()
for a, b in input_list:
    if position_list[a] < position_list[b]:
        a, b = b, a
    position_list[a] = position_list[b] + 1
    child_list[b].append(a)
total_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    total_list[p - 1] += x

count(0)
print(*total_list)

Fixed submission:
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n, q = map(int, input().split())
child_dict = defaultdict(list)
value_dict = defaultdict(lambda: 0)
rank_dict = defaultdict(lambda: 0)
for _ in range(n - 1):
    a, b = map(int, input().split())
    child_dict[a].append(b)
    rank_dict[b] += rank_dict[a] + 1

for _ in range(q):
    c, d = map(int, input().split())
    value_dict[c] += d
from collections import deque
stack = deque()
top = [k for k, v in rank_dict.items() if v == 0][0]
stack.append(top)
while stack:
    top_ = stack.pop()
    for child in child_dict[top_]:
        value_dict[child] += value_dict[top_]
    stack.extend(child_dict[top_])
ans = [value_dict[i] for i in range(1 ,n+1)]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n, q = map(int, input().split())
child_dict = defaultdict(set)
value_dict = defaultdict(lambda: 0)
for _ in range(n - 1):
    a, b = map(int, input().split())
    child_dict[a].add(b)
import copy
for _ in range(q):
    c, d = map(int, input().split())
    value_dict[c] += d
    child = child_dict[c]
    while len(child) > 0:
        k = []
        for i in child:
            value_dict[i] += d
            k.extend(child_dict[i])
        child = copy.deepcopy(k)
ans = [value_dict[i] for i in range(1 ,n+1)]
print(*ans)



Fixed submission:
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, q = map(int, input().split())
child_dict = defaultdict(set([]))
value_dict = defaultdict(lambda: 0)
for _ in range(n - 1):
    a, b = map(int, input().split())
    child_dict[a].add(b)
import copy
for _ in range(q):
    c, d = map(int, input().split())
    value_dict[c] += d
    child = child_dict[c]
    while len(child) > 0:
        k = []
        for i in child:
            value_dict[i] += d
            k.extend(child_dict[i])
        child = copy.deepcopy(k)
ans = [value_dict[i] for i in range(1 ,n+1)]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n, q = map(int, input().split())
child_dict = defaultdict(list)
value_dict = defaultdict(lambda: 0)
for _ in range(n - 1):
    a, b = map(int, input().split())
    child_dict[a].append(b)
import copy
for _ in range(q):
    c, d = map(int, input().split())
    value_dict[c] += d
    child = child_dict[c]
    while len(child) > 0:
        k = []
        for i in child:
            value_dict[i] += d
            k.extend(child_dict[i])
        child = copy.deepcopy(k)
ans = [value_dict[i] for i in range(1 ,n+1)]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)