Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def main():
  a,b=map(int,input().split())
  e=[[]for i in range(a)]

  for i in range(a-1):
    c1,c2=map(int,input().split())
    e[c1-1].append(c2-1)
    e[c2-1].append(c1-1)

  g=[[]for i in range(a)]
  f=[[0,-1]]
  ans=[0 for _ in range(a)]
  for i in range(b):
    ten,p=map(int,input().split())
    ans[ten-1]+=p
  i=0
  while len(f)!=0:
    i,fr=f.pop(0)
    for j in e[i]:
      if j==fr:
        continue
      else:
        ans[j]+=ans[i]
        f.append([j,i]) 
  print(*ans)
  
main()
    
  

  
  


Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]

e=[[]for i in range(a)]

for i in c:
  e[i[0]-1].append(i[1]-1)
  e[i[1]-1].append(i[0]-1)


g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)
    
  

  
  


Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]

e=[[]for i in range(a)]

for i in c:
  e[i[0]-1].append(i[1]-1)
  e[i[1]-1].append(i[0]-1)


g=[[]for i in range(a)]
f=[[0,-1]]
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.pop(0)
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)
    
  

  
  


Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[list(map(int,input().split())) for i in range(b)]
e=[[]for i in range(a)]

for i in c:
  e[i[0]-1].append(i[1]-1)
  e[i[1]-1].append(i[0]-1)


g=[[]for i in range(a)]
f=[[0,-1]]
ans=[0 for _ in range(a)]
for i in d:
  ans[i[0]-1]=ans[i[0]-1]+i[1]
i=0
while len(f)!=0:
  i,fr=f.pop(0)
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i])



  

  
print(*ans)
    
  

  
  


Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[list(map(int,input().split())) for i in range(b)]
e=[[]for i in range(a)]

for i in c:
  e[i[0]-1].append(i[1]-1)
  e[i[1]-1].append(i[0]-1)


g=[[]for i in range(a)]
n=0
f=[0 for _ in range(a)]
ans=[0 for _ in range(a)]
for i in d:
  ans[i[0]-1]=ans[i[0]-1]+i[1]
i=0
h=[]
while n<a:
  n+=1
  m=float("inf")
  for j,k in enumerate(e[i]):
    if f[i]==k:
      m=j
    else:
      f[k]=i
  if m!=float("inf"):
    e[i].pop(m)
  h=h+e[i]
  for j in e[i]:
    ans[j]+=ans[i]
  if len(h)!=0:
    i=h.pop()



  

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

  
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[list(map(int,input().split())) for i in range(b)]
e=[[]for i in range(a)]

for i in c:
  e[i[0]-1].append(i[1]-1)
  e[i[1]-1].append(i[0]-1)


g=[[]for i in range(a)]
n=0
i=0
f=[0 for i in range(a)]
h=[]
while n<a:
  n+=1
  m=float("inf")
  for j,k in enumerate(e[i]):
    if f[i]==k:
      m=j
    else:
      f[k]=i
  if m!=float("inf"):
    e[i].pop(m)
  h=h+(e[i])
  g[i]=g[i]+e[i]
  if len(h)!=0:
    i=h.pop()


k=[e[i]+[i]for i in range(a)]
def s(i,g):
  if g[i]==[]:
    return []
  else:
    global k
    for j in g[i]:
      k[i]=k[i]+s(j,g)
    return g[i]
    
  
s(0,g)
h=[0 for i in range(a)]
for i in d:
  for j in k[i[0]-1]:
    h[j]+=i[1]
  
print(" ".join(map(str,h)))
    
  

  
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[list(map(int,input().split())) for i in range(b)]
e=[[]for i in range(a)]

for i in c:
  e[i[0]-1].append(i[1]-1)
  e[i[1]-1].append(i[0]-1)


g=[[i]for i in range(a)]

def s(i,e,f):
  for j,k in enumerate(e[i]):
    if f==k:
      e[i].pop(j)
      break
  if e[i]==[]:
    return []
  global g
  g[i]=g[i]+e[i]
  for j in e[i]:
    g[i]=g[i]+s(j,e,i)
  return e[i]


s(0,e,0) 
h=[0 for i in range(a)]
for i in d:
  for j in g[i[0]-1]:
    h[j]+=i[1]
    
print(" ".join(map(str,h)))
    
  

  
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
e=[[]for i in range(a)]

for i in range(a-1):
  c1,c2=map(int,input().split())
  e[c1-1].append(c2-1)
  e[c2-1].append(c1-1)

g=[[]for i in range(a)]
f=deque()
f.append((0,-1))
ans=[0 for _ in range(a)]
for i in range(b):
  ten,p=map(int,input().split())
  ans[ten-1]+=p
i=0
while len(f)!=0:
  i,fr=f.popleft()
  for j in e[i]:
    if j==fr:
      continue
    else:
      ans[j]+=ans[i]
      f.append([j,i]) 
print(*ans)