Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    from collections import defaultdict
    MOD = 10**9+7

    N,Q = LMIIS()
    edge = defaultdict(list)
    E = defaultdict(list)

    X = [0]*N
    counts = [0]*N
    for _ in range(N-1):
        a,b=LMIIS()

        E[a-1].append(b-1)
        E[b-1].append(a-1)

    visited = [False]*N
    origins = [0]
    ancestors = defaultdict(list)


    for _ in range(Q):
        p,x = LMIIS()
        X[p-1] += x

    def f(o):
        visited[o] = True
        counts[o] += X[o]
        for d in E[o]:
            if visited[d] != True:
                # ancestors[d] = O
                counts[d] += counts[o]
                f(d)
    
    f(0)
            

    
    for i in counts:
        write(str(i))
        write(' ')

            





    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    from collections import defaultdict
    MOD = 10**9+7

    N,Q = LMIIS()
    edge = defaultdict(list)
    E = defaultdict(list)

    X = [0]*N
    counts = [0]*N
    for _ in range(N-1):
        a,b=LMIIS()

        E[a-1].append(b-1)
        E[b-1].append(a-1)

    visited = [False]*N




    for _ in range(Q):
        p,x = LMIIS()
        X[p-1] += x

    # def f(o):
    #     visited[o] = True
    #     counts[o] += X[o]
    #     for d in E[o]:
    #         if visited[d] != True:
    #             counts[d] += counts[o]
    #             f(d)
    # f(0)
    
    origins = [0]
    while len(origins) > 0:
        o = origins.pop()
        visited[o] = True
        counts[o] += X[o]
        for d in E[o]:
            if visited[d] != True:
                counts[d] += counts[o]
                origins.append(d)



    
    for i in counts:
        write(str(i))
        write(' ')

            





    

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    from collections import defaultdict
    MOD = 10**9+7

    N,Q = LMIIS()
    edge = defaultdict(list)
    E = defaultdict(list)
    P = []
    X = []
    counts = [0]*N
    for _ in range(N-1):
        a,b=LMIIS()

        E[a-1].append(b-1)
        E[b-1].append(a-1)

    visited = [False]*N
    origins = [0]
    while len(origins) > 0:
        o = origins.pop(0)
        visited[o] = True
        for d in E[o]:
            if visited[d] != True:
                edge[o].append(d)
                origins.append(d)
    
    for _ in range(Q):
        p,x = LMIIS()
        P.append(p-1)
        X.append(x)

    for j in range(Q):
        origins = [P[j]]
        while len(origins) > 0:
            o = origins.pop()
            counts[o] += X[j]
            origins += edge[o]
            

    for i in counts:
        write(str(i))
        write(' ')

            





    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    from collections import defaultdict
    MOD = 10**9+7

    N,Q = LMIIS()
    edge = defaultdict(list)
    E = defaultdict(list)

    X = [0]*N
    counts = [0]*N
    for _ in range(N-1):
        a,b=LMIIS()

        E[a-1].append(b-1)
        E[b-1].append(a-1)

    visited = [False]*N




    for _ in range(Q):
        p,x = LMIIS()
        X[p-1] += x

    # def f(o):
    #     visited[o] = True
    #     counts[o] += X[o]
    #     for d in E[o]:
    #         if visited[d] != True:
    #             counts[d] += counts[o]
    #             f(d)
    # f(0)
    
    origins = [0]
    while len(origins) > 0:
        o = origins.pop()
        visited[o] = True
        counts[o] += X[o]
        for d in E[o]:
            if visited[d] != True:
                counts[d] += counts[o]
                origins.append(d)



    
    for i in counts:
        write(str(i))
        write(' ')

            





    

if __name__ == '__main__':
    main()