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


def main():
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [[] for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1].append(b-1)
        e2[b-1].append(a-1)

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    used = [0] * n

    def dfs(x, p_sum):
        counters[x] += p_sum
        used[x] = 1
        for y in e2[x]:
            if used[y] == 1:
                continue
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()


Fixed submission:
import sys
sys.setrecursionlimit(10**6)


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [{} for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1][b-1] = 1
        e2[b-1][a-1] = 1

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    def dfs(x, p_sum):
        counters[x] += p_sum
        for y in e2[x]:
            del e2[y][x]
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()

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


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [{} for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1][b-1] = 1
        e2[b-1][a-1] = 1

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    def dfs(x, p_sum):
        counters[x] += p_sum
        for y in e2[x]:
            del e2[y][x]
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()


Fixed submission:
import sys
sys.setrecursionlimit(10**6)


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [{} for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1][b-1] = 1
        e2[b-1][a-1] = 1

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    def dfs(x, p_sum):
        counters[x] += p_sum
        for y in e2[x]:
            del e2[y][x]
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()

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


def main():
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [[] for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1].append(b-1)
        e2[b-1].append(a-1)

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    used = set()

    def dfs(x, p_sum):
        used.add(x)
        counters[x] += p_sum
        for y in e2[x]:
            if y in used:
                continue
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()


Fixed submission:
import sys
sys.setrecursionlimit(10**6)


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [{} for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1][b-1] = 1
        e2[b-1][a-1] = 1

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    def dfs(x, p_sum):
        counters[x] += p_sum
        for y in e2[x]:
            del e2[y][x]
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()