Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,q=map(int,input().split())
  a=[[i] for i in range(n+1)]
  b=[0 for i in range(n+1)]
  
  for i in range(n-1):
    x,y=map(int,input().split())
    for j in range(n-1):
      if x in a[j]:
        a[j].append(y)
#        print(a)
 
#  print("aaa",a)
  for i in range(q):
    x,y=map(int,input().split())
#    print("c,y",x,y)
#    print("ax",a[x])
#    print("B",b)
    for j in a[x]:
#      print("j",j)
      b[j-1]+=y
#      print(b)

       
  print(*b[:n])

if __name__ == "__main__":
    main()

Fixed submission:
def main():
  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)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,q=map(int,input().split())
  a=[[i] for i in range(n+1)]
  b=[0 for i in range(n+1)]
  
  for i in range(n-1):
    x,y=map(int,input().split())
    for j in range(n-1):
      if x in a[j]:
        a[j].append(y)
#        print(a)
 
#  print("aaa",a)
  for i in range(q):
    x,y=map(int,input().split())
#    print("c,y",x,y)
#    print("ax",a[x])
#    print("B",b)
    for j in a[x]:
#      print("j",j)
      b[j-1]+=y
#      print(b)

       
  print(*b[:n])

if __name__ == "__main__":
    main()

Fixed submission:
def main():
  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)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,q=map(int,input().split())
  a=[[i] for i in range(n+1)]
  b=[0 for i in range(n+1)]
  
  for i in range(n-1):
    x,y=map(int,input().split())
    a[x].append(y)
#    print(a)
  
  for i in range(n):
    for j in range(i+1,n):
      if a[j][0] in a[i]:
        for k in a[j]:
          if k not in a[i]:
            a[i].append(k)
#  print("aaa",a)
  for i in range(q):
    x,y=map(int,input().split())
#    print("c,y",x,y)
#    print("ax",a[x])
#    print("B",b)
    for j in a[x]:
#      print("j",j)
      b[j-1]+=y
#      print(b)

       
  print(*b[:n])

if __name__ == "__main__":
    main()

Fixed submission:
def main():
  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)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,q=map(int,input().split())
  a=[[i] for i in range(n+1)]
  b=[0 for i in range(n+1)]
  
  for i in range(n-1):
    x,y=map(int,input().split())
    a[x].append(y)
#    print(a)
  
  for i in range(n):
    for j in range(i+1,n):
      if a[j][0] in a[i]:
        for k in a[j]:
          if k not in a[i]:
            a[i].append(k)
#  print("aaa",a)
  for i in range(q):
    x,y=map(int,input().split())
#    print("c,y",x,y)
#    print("ax",a[x])
#    print("B",b)
    for j in a[x]:
#      print("j",j)
      b[j-1]+=y
#      print(b)

       
  print(*b[:n])

if __name__ == "__main__":
    main()

Fixed submission:
def main():
  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)
if __name__ == "__main__":
    main()