Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split(" "))
A = []

B = [0 for j in range(N)]
for i in range(N-1):
    A.append(list(map(int,input().split(" "))))
    
A = sorted(A)
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]


for i in range(N-1):
        B[A[i][1]-1] += B[A[i][0]-1]

for i in range(N):
        print(B[i],end=" ")

Fixed submission:
N,Q = map(int,input().split(" "))
A = [0]*N

B = [0 for j in range(N)]
for i in range(N-1):
    a,b = map(int,input().split(" "))
    A[b-1] = a-1
    
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(1,N):
        B[i] += B[A[i]]
for i in range(N):
        print(B[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split(" "))
A = []

B = [0 for j in range(N)]
for i in range(N-1):
    tmp = list(map(int,input().split(" ")))
    A.append(tmp)
A.sort()
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]


for i in range(N-1):
        B[A[i][1]-1] += B[A[i][0]-1]

for i in range(N):
        print(B[i],end=" ")

Fixed submission:
N,Q = map(int,input().split(" "))
A = [0]*N

B = [0 for j in range(N)]
for i in range(N-1):
    a,b = map(int,input().split(" "))
    A[b-1] = a-1
    
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(1,N):
        B[i] += B[A[i]]
for i in range(N):
        print(B[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split(" "))
A = []

B = [0 for j in range(N)]
for i in range(N-1):
    tmp = list(map(int,input().split(" ")))
    A.append(tmp)
A.sort()
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]


for i in range(N-1):
        B[A[i][1]-1] += B[A[i][0]-1]

for i in range(N):
        print(B[i],end=" ")

Fixed submission:
N,Q = map(int,input().split(" "))
A = [0]*N

B = [0 for j in range(N)]
for i in range(N-1):
    a,b = map(int,input().split(" "))
    A[b-1] = a-1
    
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(1,N):
        B[i] += B[A[i]]
for i in range(N):
        print(B[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split(" "))
A = []
A.append(-1)

B = [0 for j in range(N)]
for i in range(N-1):
    tmp = list(map(int,input().split(" ")))
    A.append(tmp[0])

for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(N):
    ans = 0
    p = i
    while(1):
        ans += B[p]
        p = A[p]-1
        if p <= -1:
            break;
    print(ans,end=' ')


Fixed submission:
N,Q = map(int,input().split(" "))
A = [0]*N

B = [0 for j in range(N)]
for i in range(N-1):
    a,b = map(int,input().split(" "))
    A[b-1] = a-1
    
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(1,N):
        B[i] += B[A[i]]
for i in range(N):
        print(B[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split(" "))
A = [[0,1,0]]
B = []
for i in range(N-1):
    A.append(list(map(int,input().split(" "))))
    A[i+1].append(0)
for j in range(Q):
    B.append(list(map(int,input().split(" "))))

for j in range(Q):
    tmp=[]
    for i in range(N):
        if A[i][1]==B[j][0] or A[i][0]==B[j][0] or A[i][0] in tmp:
            A[i][2]+=B[j][1]
            tmp.append(A[i][1])


for i in range(N):
    print(A[i][2],end=" ")


Fixed submission:
N,Q = map(int,input().split(" "))
A = [0]*N

B = [0 for j in range(N)]
for i in range(N-1):
    a,b = map(int,input().split(" "))
    A[b-1] = a-1
    
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(1,N):
        B[i] += B[A[i]]
for i in range(N):
        print(B[i],end=" ")