Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        path = defaultdict(list)
        N, Q = map(int, input().split())
        freq = [0] * N
        for i in range(N-1):
            ai, bi = map(int, input().split())
            path[ai-1].append(bi-1)
            # path[bi-1].append(ai-1)

        for i in range(Q):
            p, x = map(int, input().split())
            freq[p-1] += x

        stack = [(0, 0)]
        seen = set()
        res = [0] * N
        while stack:
            node, cum = stack.pop(0)
            # seen.add(node)
            val = freq[node] + cum
            res[node] = val
            for other in path[node]:
                # if other not in seen:
                stack.append((other, val))
        print(' '.join(map(str, res)))

if __name__ == '__main__':
    Solution().main()

Fixed submission:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        path = defaultdict(list)
        N, Q = map(int, input().split())
        freq = [0] * N
        for i in range(N-1):
            ai, bi = map(int, input().split())
            path[ai-1].append(bi-1)
            # path[bi-1].append(ai-1)

        for i in range(Q):
            p, x = map(int, input().split())
            freq[p-1] += x

        stack = [(0, 0)]
        seen = set()
        res = freq[:]
        for i in range(N):
            for other in path[i]:
                res[other] += res[i]

        print(' '.join(map(str, res)))


if __name__ == '__main__':
    Solution().main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        path = defaultdict(list)
        N, Q = map(int, input().split())
        freq = [0] * N
        for i in range(N-1):
            ai, bi = map(int, input().split())
            path[ai-1].append(bi-1)
            path[bi-1].append(ai-1)

        for i in range(Q):
            p, x = map(int, input().split())
            freq[p-1] += x

        stack = [(0, 0)]
        seen = set()
        res = [0] * N
        while stack:
            node, cum = stack.pop(0)
            seen.add(node)
            val = freq[node] + cum
            res[node] = val
            for other in path[node]:
                if other not in seen:
                    stack.append((other, val))
        print(' '.join(map(str, res)))

if __name__ == '__main__':
    Solution().main()

Fixed submission:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        path = defaultdict(list)
        N, Q = map(int, input().split())
        freq = [0] * N
        for i in range(N-1):
            ai, bi = map(int, input().split())
            path[ai-1].append(bi-1)
            # path[bi-1].append(ai-1)

        for i in range(Q):
            p, x = map(int, input().split())
            freq[p-1] += x

        stack = [(0, 0)]
        seen = set()
        res = freq[:]
        for i in range(N):
            for other in path[i]:
                res[other] += res[i]

        print(' '.join(map(str, res)))


if __name__ == '__main__':
    Solution().main()