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

sys.setrecursionlimit(10**9)


def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

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

    visited = [False]*N
    visited[0] = True

    def dfs(v: int):
        nonlocal visited
        nonlocal cnt
        if all(visited):
            print(*cnt)
            sys.exit()
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            dfs(n)
        return

    dfs(0)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**9)


def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

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

    visited = [False]*N
    visited[0] = True
    q = deque([0])
    while q:
        v = q.pop()
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            q.append(n)
    print(*cnt)


if __name__ == "__main__":
    main()

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

sys.setrecursionlimit(10**9)


def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

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

    visited = [False]*N
    visited[0] = True

    def dfs(v: int):
        nonlocal visited
        nonlocal cnt
        if all(visited):
            print(*cnt)
            sys.exit()
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            dfs(n)
        return

    dfs(0)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**9)


def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

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

    visited = [False]*N
    visited[0] = True
    q = deque([0])
    while q:
        v = q.pop()
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            q.append(n)
    print(*cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

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

    visited = [False]*N
    visited[0] = True

    def dfs(v: int):
        nonlocal visited
        nonlocal cnt
        if all(visited):
            return
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            dfs(n)
        return

    dfs(0)
    print(*cnt)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**9)


def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

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

    visited = [False]*N
    visited[0] = True
    q = deque([0])
    while q:
        v = q.pop()
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            q.append(n)
    print(*cnt)


if __name__ == "__main__":
    main()