Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
from copy import deepcopy

sys.setrecursionlimit(10 ** 5 + 5)

n, q = list(map(int, input().split()))
edge = defaultdict(set)
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

tree = defaultdict(lambda: {"count": 0, "children": set()})
ROOT = 0


def rec(parent, ancestors):
    # print(parent)
    for ancestor in ancestors:
        for child in edge[parent]:
            if child in ancestors:
                continue
            tree[ancestor]["children"].add(child)
            new_ancestors = deepcopy(ancestors)
            new_ancestors.add(child)
            rec(child, new_ancestors)


rec(ROOT, set([ROOT]))

# print(tree)

opr = []
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr.append((p, x))

score = [0] * n
for p, x in opr:
    score[p] += x
    for child in tree[p]["children"]:
        score[child] += x

answer = " ".join(map(str, score))
print(answer)

Fixed submission:
n, q = list(map(int, input().split()))
# NG: [set()] * n <- all points same set
edge = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

opr = [0] * n
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr[p] += x

score = [-1] * n
q = [(0, 0)]
while q:
    # print(*q)
    node, w = q.pop()
    w += opr[node]
    score[node] = w
    # print(*score)
    for child in edge[node]:
        if score[child] == -1:
            q.append((child, w))

print(*score)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
from copy import deepcopy

sys.setrecursionlimit(10 ** 5 + 5)

n, q = list(map(int, input().split()))
edge = defaultdict(set)
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

tree = defaultdict(lambda: {"count": 0, "children": set()})
ROOT = 0


def rec(parent, ancestors):
    # print(parent)
    for child in edge[parent]:
        if child in ancestors:
            continue

        for ancestor in ancestors:
            tree[ancestor]["children"].add(child)
        new_ancestors = deepcopy(ancestors)
        new_ancestors.add(child)
        rec(child, new_ancestors)


rec(ROOT, set([ROOT]))

# print(tree)

opr = []
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr.append((p, x))

score = [0] * n
for p, x in opr:
    score[p] += x
    for child in tree[p]["children"]:
        score[child] += x

answer = " ".join(map(str, score))
print(answer)

Fixed submission:
n, q = list(map(int, input().split()))
# NG: [set()] * n <- all points same set
edge = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

opr = [0] * n
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr[p] += x

score = [-1] * n
q = [(0, 0)]
while q:
    # print(*q)
    node, w = q.pop()
    w += opr[node]
    score[node] = w
    # print(*score)
    for child in edge[node]:
        if score[child] == -1:
            q.append((child, w))

print(*score)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
from copy import deepcopy

sys.setrecursionlimit(10 ** 5 + 5)

n, q = list(map(int, input().split()))
edge = defaultdict(set)
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

tree = defaultdict(lambda: {"count": 0, "children": set()})
ROOT = 0


def rec(parent, ancestors):
    # print(parent)
    for child in edge[parent]:
        if child in ancestors:
            continue

        for ancestor in ancestors:
            tree[ancestor]["children"].add(child)
        new_ancestors = deepcopy(ancestors)
        new_ancestors.add(child)
        rec(child, new_ancestors)


rec(ROOT, set([ROOT]))

# print(tree)

opr = []
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr.append((p, x))

score = [0] * n
for p, x in opr:
    score[p] += x
    for child in tree[p]["children"]:
        score[child] += x

answer = " ".join(map(str, score))
print(answer)

Fixed submission:
n, q = list(map(int, input().split()))
# NG: [set()] * n <- all points same set
edge = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

opr = [0] * n
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr[p] += x

score = [-1] * n
q = [(0, 0)]
while q:
    # print(*q)
    node, w = q.pop()
    w += opr[node]
    score[node] = w
    # print(*score)
    for child in edge[node]:
        if score[child] == -1:
            q.append((child, w))

print(*score)