Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))
 
a.sort()
 
for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y
 
for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]
 
print(*c)

Fixed submission:
n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))

a.sort()

for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y

for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, q = (int(_) for _ in input().split())  
arr = np.array([[1 if i == j else 0 for i in range(n)] for j in range(n)])
output = np.array([0 for i in range(n)])
ab = []
for i in range(n-1):
  a, b = (int(_) for _ in input().split()) 
  ab.append([a, b])
  
for x in reversed(ab):
  a = x[0]
  b = x[1]
  arr[a-1] = arr[a-1] | arr[b-1]

for i in range(q):
  p, q = (int(_) for _ in input().split()) 
  output += arr[p-1] * q
    
print(' '.join([str(x) for x in output]))

Fixed submission:
n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))

a.sort()

for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y

for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, q = (int(_) for _ in input().split())  
arr = np.array([[1 if i == j else 0 for i in range(n)] for j in range(n)])
output = np.array([0 for i in range(n)])

for i in range(n-1):
  a, b = (int(_) for _ in input().split()) 
  arr[a-1][b-1] = 1
  for x in range(a-1):
    if arr[x][a-1] == 1:
      arr[x][b-1] = 1

for i in range(q):
  p, q = (int(_) for _ in input().split()) 
  output += arr[p-1] * q
    
print(' '.join([str(x) for x in output]))

Fixed submission:
n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))

a.sort()

for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y

for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = (int(_) for _ in input().split())  
arr = [[1 if i == j else 0 for i in range(n)] for j in range(n)]
output = [0 for i in range(n)]

for i in range(n-1):
  a, b = (int(_) for _ in input().split()) 
  arr[a-1][b-1] = 1
  for x in range(a-1):
    if arr[x][a-1] == 1:
      arr[x][b-1] = 1

for i in range(q):
  p, q = (int(_) for _ in input().split()) 
  for i, x in enumerate(arr[p-1]):
    if x == 1:
      output[i] += q
    
print(' '.join([str(x) for x in output]))
  

Fixed submission:
n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))

a.sort()

for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y

for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = (int(_) for _ in input().split())  
arr = [[1 if i == j else 0 for i in range(n)] for j in range(n)]
output = [0 for i in range(n)]

for i in range(n-1):
  a, b = (int(_) for _ in input().split()) 
  arr[a-1][b-1] = 1
  for x in range(a-1):
    if arr[x][a-1] == 1:
      arr[x][b-1] = 1

for i in range(q):
  p, q = (int(_) for _ in input().split()) 
  for i, x in enumerate(arr[p-1]):
    if x == 1:
      output[i] += q
    
print(' '.join([str(x) for x in output]))

Fixed submission:
n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))

a.sort()

for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y

for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]

print(*c)