Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
ab=[[_] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    ab[max(a,b)-1].append(min(a,b))
ab[0].append(-1)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
ab.sort(key=lambda x: x[1])
for i in range(1,n):
    for j in range(1,len(ab[i])):
        ans[ab[i][0]]+=ans[ab[i][j]-1]
print(*ans)


Fixed submission:
from collections import deque
n,q=map(int,input().split())
num=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    num[a-1].append(b)
    num[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
queue=deque()
queue.append(0)
seen=[False]*n
for i in range(n):
    if len(queue)==0:
        break
    num1=queue.popleft()
    seen[num1]=True
    num2=num[num1]
    for j in range(len(num2)):
        if seen[num2[j]-1]==False:
            ans[num2[j]-1]+=ans[num1]
            queue.append(num2[j]-1)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    ab[a-1].append(b)
    ab[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
yn=[0]*n
yn[0]=1
n1=1
queue=[]
queue2=[]
for i in range(n+10):
    for j in range(len(ab[n1-1])):
        n2=ab[n1-1][j]
        if yn[n2-1]==0:
            yn[n2-1]=1
            queue.append(n2)
    for j in range(len(queue)):
        ans[queue[0]-1]+=ans[n1-1]
        queue2.append(queue.pop(0))
    if len(queue)==0 and len(queue2)==0:
        break
    n1=queue2.pop(0)
print(*ans)


Fixed submission:
from collections import deque
n,q=map(int,input().split())
num=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    num[a-1].append(b)
    num[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
queue=deque()
queue.append(0)
seen=[False]*n
for i in range(n):
    if len(queue)==0:
        break
    num1=queue.popleft()
    seen[num1]=True
    num2=num[num1]
    for j in range(len(num2)):
        if seen[num2[j]-1]==False:
            ans[num2[j]-1]+=ans[num1]
            queue.append(num2[j]-1)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    ab[a-1].append(b)
    ab[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
yn=[0]*n
yn[0]=1
n1=1
queue=[]
queue2=[]
for i in range(n+10):
    for j in range(len(ab[n1-1])):
        if yn[ab[n1-1][j]-1]==0:
            yn[ab[n1-1][j]-1]=1
            queue.append(ab[n1-1][j])
    for j in range(len(queue)):
        ans[queue[0]-1]+=ans[n1-1]
        queue2.append(queue[0])
        del(queue[0])
    if len(queue)==0 and len(queue2)==0:
        break
    n1=queue2.pop(-1)
print(*ans)


Fixed submission:
from collections import deque
n,q=map(int,input().split())
num=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    num[a-1].append(b)
    num[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
queue=deque()
queue.append(0)
seen=[False]*n
for i in range(n):
    if len(queue)==0:
        break
    num1=queue.popleft()
    seen[num1]=True
    num2=num[num1]
    for j in range(len(num2)):
        if seen[num2[j]-1]==False:
            ans[num2[j]-1]+=ans[num1]
            queue.append(num2[j]-1)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    ab[a-1].append(b)
    ab[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
yn=[0]*n
yn[0]=1
n1=1
queue=[]
queue2=[]
for i in range(n+10):
    for j in range(len(ab[n1-1])):
        if yn[ab[n1-1][j]-1]==0:
            yn[ab[n1-1][j]-1]=1
            queue.append(ab[n1-1][j])
    for j in range(len(queue)):
        ans[queue[0]-1]+=ans[n1-1]
        queue2.append(queue[0])
        del(queue[0])
    if len(queue)==0 and len(queue2)==0:
        break
    n1=queue2.pop(-1)
print(*ans)


Fixed submission:
from collections import deque
n,q=map(int,input().split())
num=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    num[a-1].append(b)
    num[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
queue=deque()
queue.append(0)
seen=[False]*n
for i in range(n):
    if len(queue)==0:
        break
    num1=queue.popleft()
    seen[num1]=True
    num2=num[num1]
    for j in range(len(num2)):
        if seen[num2[j]-1]==False:
            ans[num2[j]-1]+=ans[num1]
            queue.append(num2[j]-1)
for i in ans:
    print(i)