Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def f(ab: list, parent: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    for j in ab[i]:
        if j != parent[i]:
            parent[j] = i
            f(ab, parent, j)

def g(ab: list, parent: list, ans: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    for j in ab[i]:
        if j != parent[i]:
            ans[j] += ans[i]
            g(ab, parent, ans, j)

def main():
    N, Q = map(int, input().split())
    ab = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    parent = [-1] * N
    f(ab, parent)
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    g(ab, parent, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__': main()

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

def g(ab: list, ans: list, check: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    check[i] = False
    for j in ab[i]:
        if check[j]:
            ans[j] += ans[i]
            g(ab, ans, check, j)

def main():
    N, Q = map(int, input().split())
    ab = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    ans = [0] * N
    check = [True] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    g(ab, ans, check)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__': main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def f(ab: list, parent: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    for j in ab[i]:
        if j != parent[i]:
            parent[j] = i
            f(ab, parent, j)

def g(ab: list, parent: list, ans: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    for j in ab[i]:
        if j != parent[i]:
            ans[j] += ans[i]
            g(ab, parent, ans, j)

def main():
    N, Q = map(int, input().split())
    ab = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    parent = [-1] * N
    f(ab, parent)
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    g(ab, parent, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__': main()

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

def g(ab: list, ans: list, check: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    check[i] = False
    for j in ab[i]:
        if check[j]:
            ans[j] += ans[i]
            g(ab, ans, check, j)

def main():
    N, Q = map(int, input().split())
    ab = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    ans = [0] * N
    check = [True] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    g(ab, ans, check)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__': main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def f(ab: list, parent: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    for j in ab[i]:
        if j != parent[i]:
            parent[j] = i
            f(ab, parent, j)

def g(ab: list, parent: list, ans: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    for j in ab[i]:
        if j != parent[i]:
            ans[j] += ans[i]
            g(ab, parent, ans, j)

def main():
    N, Q = map(int, input().split())
    ab = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    parent = [-1] * N
    f(ab, parent)
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    g(ab, parent, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__': main()

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

def g(ab: list, ans: list, check: list, i: int = 0):
    if len(ab[i]) == 1 and i != 0:
        return
    check[i] = False
    for j in ab[i]:
        if check[j]:
            ans[j] += ans[i]
            g(ab, ans, check, j)

def main():
    N, Q = map(int, input().split())
    ab = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    ans = [0] * N
    check = [True] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    g(ab, ans, check)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__': main()