Buggy python submission (verdict: Runtime Error):
import sys


def count(i, r):
    counter[i] += counter[r] if r >= 0 else 0
    for e in es[i]:
        count(e, i)


if __name__ == "__main__":
    sys.setrecursionlimit(2*(10**5))
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    es = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a-1].append(b-1)
    counter = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        counter[p-1] += x
    count(0, -1)
    print(*counter)


Fixed submission:
import sys


def count(i, r, value):
    value += rc[i]
    counter[i] = value
    for e in es[i]:
        if e != r:
            count(e, i, value)


if __name__ == "__main__":
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    es = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a-1].append(b-1)
        es[b-1].append(a-1)
    counter = [0]*N
    rc = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        rc[p-1] += x
    count(0, -1, 0)
    print(*counter)

Buggy python submission (verdict: Runtime Error):
import sys


def count(i, c):
    counter[i] = c+rc[i]
    for e in es[i]:
        if counter[e] == 0:
            count(e, counter[i])


if __name__ == "__main__":
    sys.setrecursionlimit(2*(10**5))
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    es = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a-1].append(b-1)
    counter = [0]*N
    rc = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        rc[p-1] += x
    count(0, 0)
    print(*counter)


Fixed submission:
import sys


def count(i, r, value):
    value += rc[i]
    counter[i] = value
    for e in es[i]:
        if e != r:
            count(e, i, value)


if __name__ == "__main__":
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    es = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a-1].append(b-1)
        es[b-1].append(a-1)
    counter = [0]*N
    rc = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        rc[p-1] += x
    count(0, -1, 0)
    print(*counter)

Buggy python submission (verdict: Runtime Error):
import sys


def count(i, x):
    counter[i] += x
    for e in es[i]:
        count(e, x)


if __name__ == "__main__":
    sys.setrecursionlimit(2*(10**5))
    N, Q = map(int, input().split())
    es = [[] for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a].append(b)
    counter = [0 for _ in range(N+1)]
    for _ in range(Q):
        p, x = map(int, input().split())
        count(p, x)
    for i in range(1, N+1):
        if i == N:
            print(counter[i], end="\n")
        else:
            print(counter[i], end=" ")


Fixed submission:
import sys


def count(i, r, value):
    value += rc[i]
    counter[i] = value
    for e in es[i]:
        if e != r:
            count(e, i, value)


if __name__ == "__main__":
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    es = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a-1].append(b-1)
        es[b-1].append(a-1)
    counter = [0]*N
    rc = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        rc[p-1] += x
    count(0, -1, 0)
    print(*counter)