Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))

Fixed submission:
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))

Buggy python submission (verdict: Runtime Error):
 
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))
#from collections import deque

n,q = map(int,input().split())

a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]

for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])

p = [0] * q
x = [0] * q


for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1

plus = [0] * n

for j in range(q):
    plus[p[j]] += x[j]

state = [0] * n
state[0] = 1
cur = [0]

child = [[] for _ in range(n)]
par = [0] * n

ranklist = [[1]]

#print(cur)
#print(info)

while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]

ans = [0] * n
ans[0] = plus[0]

for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]

print(" ".join(map(str,ans)))


Fixed submission:
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))

Buggy python submission (verdict: Runtime Error):
 
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))
#from collections import deque

n,q = map(int,input().split())

a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]

for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])

p = [0] * q
x = [0] * q


for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1

plus = [0] * n

for j in range(q):
    plus[p[j]] += x[j]

state = [0] * n
state[0] = 1
cur = [0]

child = [[] for _ in range(n)]
par = [0] * n

ranklist = [[1]]

#print(cur)
#print(info)

while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]

ans = [0] * n
ans[0] = plus[0]

for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]

print(" ".join(map(str,ans)))


Fixed submission:
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))

Buggy python submission (verdict: Time Limit Exceeded):
#from collections import deque

n,q = map(int,input().split())

a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]

for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])

p = [0] * q
x = [0] * q


for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1

plus = [0] * n

for j in range(q):
    plus[p[j]] += x[j]

state = [0] * n
state[0] = 1
cur = [0]

child = [[] for _ in range(n)]
par = [0] * n

ranklist = [[1]]

#print(cur)
#print(info)

while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]

ans = [0] * n
ans[0] = plus[0]

for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]

print(" ".join(map(str,ans)))

Fixed submission:
n,q = map(int,input().split())
 
a = [0] * (n-1)
b = [0] * (n-1)
info = [[] for _ in range(n)]
 
for i in range(n-1):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    info[a[i]].append(b[i])
    info[b[i]].append(a[i])
 
p = [0] * q
x = [0] * q
 
 
for j in range(q):
    p[j],x[j] = map(int,input().split())
    p[j] -= 1
 
plus = [0] * n
 
for j in range(q):
    plus[p[j]] += x[j]
 
state = [0] * n
state[0] = 1
cur = [0]
 
child = [[] for _ in range(n)]
par = [0] * n
 
ranklist = [[1]]
 
#print(cur)
#print(info)
 
while cur != []:
    cur2 = []
    ranklist.append([])
    for obj in cur:
        for obj2 in info[obj]:
            if state[obj2] == 0:
                state[obj2] = 1
                #child[obj].append(obj2)
                par[obj2] = obj
                cur2.append(obj2)
                ranklist[-1].append(obj2)
    cur = cur2[:]
 
ans = [0] * n
ans[0] = plus[0]
 
for l in ranklist:
    for t in l:
        ans[t] = ans[par[t]] + plus[t]
 
print(" ".join(map(str,ans)))