Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, q = map(int, input().split())

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

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

    def dfs(v, p):
        for u in tree[v]:
            if u == p:
                continue
            cnt[u] += cnt[v]
            dfs(u, v)

    dfs(0, -1)
    print(*cnt)


if __name__ == '__main__':
    resolve()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())

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

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

def dfs(v, p):
    for u in tree[v]:
        if u == p:
            continue
        else:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print(*ans)

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

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, q = map(int, input().split())

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

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

    def dfs(v, p):
        for u in tree[v]:
            if u == p:
                continue
            cnt[u] += cnt[v]
            dfs(u, v)

    dfs(0, -1)
    print(*cnt)


if __name__ == '__main__':
    resolve()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())

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

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

def dfs(v, p):
    for u in tree[v]:
        if u == p:
            continue
        else:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print(*ans)

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

n, q = map(int, input().split())

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

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

def dfs(v, p):
    for u in tree[v]:
        if u == p:
            continue
        else:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print(*ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())

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

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

def dfs(v, p):
    for u in tree[v]:
        if u == p:
            continue
        else:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print(*ans)