Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
 
N, Q = (int(x) for x in input().split())
 
dic = {}
for i in range(N) :
    dic[i+1] = []
 
for i in range(N-1) :
    a, b = (int(x) for x in input().split())
    dic[a].append(b)
    for n in dic.keys() :
        if a in dic[n] :
            dic[n].append(b)
 
SUM = [0]*n #np.zeros(N, dtype=np.int)
 
for i in range(Q) :
    p, x = (int(x) for x in input().split())
    SUM[p-1] = SUM[p-1] + x
    for n in dic[p] :
        SUM[n-1] = SUM[n-1] + x
 
print(' '.join(map(str, SUM)))

Fixed submission:

import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}

for i in range(N-1) :
    #a, b = (int(x) for x in input().split())
    a, b = map(int,input().split())
    dic[b] = a

#SUM = np.zeros(N, dtype=np.int)
SUM = [0]*N

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

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}

for i in range(N-1) :
    #a, b = (int(x) for x in input().split())
    a, b = map(int,input().split())
    dic[b] = a

SUM = np.zeros(N, dtype=np.int)

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

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

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

Fixed submission:

import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}

for i in range(N-1) :
    #a, b = (int(x) for x in input().split())
    a, b = map(int,input().split())
    dic[b] = a

#SUM = np.zeros(N, dtype=np.int)
SUM = [0]*N

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

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}
#for i in range(N) :
#    dic[i+1] = []

for i in range(N-1) :
    a, b = (int(x) for x in input().split())
    #dic[a].append(b)
    #dic[b].append(a)
    dic[b] = a
    #for n in dic.keys() :
    #    if a in dic[n] :
    #        dic[n].append(b)

SUM = np.zeros(N, dtype=np.int)

for i in range(Q) :
    p, x = (int(x) for x in input().split())
    SUM[p-1] = SUM[p-1] + x
    #for n in dic[p] :
    #    SUM[n-1] = SUM[n-1] + x

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

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

Fixed submission:

import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}

for i in range(N-1) :
    #a, b = (int(x) for x in input().split())
    a, b = map(int,input().split())
    dic[b] = a

#SUM = np.zeros(N, dtype=np.int)
SUM = [0]*N

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

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}
for i in range(N) :
    dic[i+1] = []

for i in range(N-1) :
    a, b = (int(x) for x in input().split())
    dic[a].append(b)
    for n in dic.keys() :
        if a in dic[n] :
            dic[n].append(b)

SUM = np.zeros(N, dtype=np.int)

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

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

Fixed submission:

import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}

for i in range(N-1) :
    #a, b = (int(x) for x in input().split())
    a, b = map(int,input().split())
    dic[b] = a

#SUM = np.zeros(N, dtype=np.int)
SUM = [0]*N

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

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

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