Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import sys
  input = sys.stdin.readline
  from collections import deque
  
  n,q=map(int,input().split())
  ab=[[] for _ in range(n+1)]
  for _ in range(n-1):
    a,b=map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
  ans=[0]*(n+1)
  for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x
  
  l,parent=deque([1]),[0]*(n+1)
  while l:
    x=l.popleft()
    for i in ab[x]:
      if not i in parent or i in l:
        l.append(i)
        ans[i]+=ans[x]
        parent[i]=x
      
  print(*ans[1:])
if __name__=='__main__':
  main()

Fixed submission:
def main():
  import sys
  input = sys.stdin.readline
  from collections import deque
  
  n,q=map(int,input().split())
  ab=[[] for _ in range(n+1)]
  for _ in range(n-1):
    a,b=map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
  ans=[0]*(n+1)
  for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x
  
  l,parent=deque([1]),[0]*(n+1)
  parent[1]=1
  while l:
    x=l.popleft()
    for i in ab[x]:
      if parent[i]:
        continue
      l.append(i)
      ans[i]+=ans[x]
      parent[i]=1
      
  print(*ans[1:])
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,q=map(int,input().split())
ab=[[] for _ in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  ab[a].append(b)
  ab[b].append(a)
px=[tuple(map(int,input().split())) for _ in range(q)]

ans=[0]*(n+1)
for i in range(q):
  ans[px[i][0]]+=px[i][1]
l,m=deque([1]),[]
while l:
  x=l.popleft()
  m.append(x)
  for i in ab[x]:
    if not i in m or i in l:
      l.append(i)
      ans[i]+=ans[x]
      
print(*ans[1:])

Fixed submission:
def main():
  import sys
  input = sys.stdin.readline
  from collections import deque
  
  n,q=map(int,input().split())
  ab=[[] for _ in range(n+1)]
  for _ in range(n-1):
    a,b=map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
  ans=[0]*(n+1)
  for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x
  
  l,parent=deque([1]),[0]*(n+1)
  parent[1]=1
  while l:
    x=l.popleft()
    for i in ab[x]:
      if parent[i]:
        continue
      l.append(i)
      ans[i]+=ans[x]
      parent[i]=1
      
  print(*ans[1:])
if __name__=='__main__':
  main()

Buggy python submission (verdict: Runtime Error):
n,q = int(input().split())
a = []
b = []
for i in range(n-1):
  a1,b1=[int(i) for i in input().split()]
  a.append(a1)
  b.append(b1)
p = []
x = []
for j in range(q):
  p1,x1=[int(j) for j in input().split()]
  p.append(p1)
  x.append(x1)
c = [0]*n
for j in range(q):
  for i in range(n-1):
    if p[j] == a[i]:
      c[a[i]-1] += x[j]
      c[b[i]-1] += x[j]
      for l in range(i,n-1):
        if b[i] == a[l]:
          c[a[l]-1] += x[j]
          c[b[l]-1] += x[j]
print(c)

Fixed submission:
def main():
  import sys
  input = sys.stdin.readline
  from collections import deque
  
  n,q=map(int,input().split())
  ab=[[] for _ in range(n+1)]
  for _ in range(n-1):
    a,b=map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
  ans=[0]*(n+1)
  for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x
  
  l,parent=deque([1]),[0]*(n+1)
  parent[1]=1
  while l:
    x=l.popleft()
    for i in ab[x]:
      if parent[i]:
        continue
      l.append(i)
      ans[i]+=ans[x]
      parent[i]=1
      
  print(*ans[1:])
if __name__=='__main__':
  main()