CodeEff/ECCO huggingface dataset:
# Original solution
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(eval(input())) for _ in range(n)]

n,q = get_nums_l()

lines = sys.stdin.readlines()
edges = list([list(map(int, s.split(" "))) for s in lines[:n-1]])
queries = list([list(map(int, s.split(" "))) for s in lines[n-1:]])

scores = [0] * (n+1)

for q in queries:
    scores[q[0]] += q[1]

queue = deque()
mark = [False] * (n+1)
mark[1] = True

for e in edges:
    queue.append(e)

while queue:
    e = queue.popleft()
    
    a = e[0]
    b = e[1]
    if mark[a]:
        scores[b] += scores[a]
        mark[b] = True
    elif mark[b]:
        scores[a] += scores[b]
        mark[a] = True
    else:
        queue.append(e)
        print()

print((" ".join(map(str,scores[1:]))))


# Optimized solution
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(eval(input())) for _ in range(n)]

n,q = get_nums_l()

lines = sys.stdin.readlines()
edges = list([list(map(int, s.split(" "))) for s in lines[:n-1]])
queries = list([list(map(int, s.split(" "))) for s in lines[n-1:]])

scores = [0] * (n+1)

for q in queries:
    scores[q[0]] += q[1]

queue = deque()
mark = [False] * (n+1)
mark[1] = True


childrens = [ [] for _ in range(n+1) ]
for e in edges:
    a = e[0]
    b = e[1]
    childrens[a].append(b)
    childrens[b].append(a)


queue.append(1)

while queue:
    a = queue.popleft()
    children = childrens[a]
    for b in children:
        if not mark[b]:
            scores[b] += scores[a]
            mark[b] = True
            queue.append(b)

print((" ".join(map(str,scores[1:]))))
# Original solution
N, Q = list(map(int, input().split()))
E = [[] for _ in range(N)]
C = [0] * N
C[0] = 0
for _ in range(N - 1):
  a, b = list(map(int, input().split()))
  E[a - 1].append(b - 1)
  E[b - 1].append(a - 1)
for _ in range(Q):
  p, x = list(map(int, input().split()))
  C[p - 1] += x
D = [-1] * N
D[0] = 0
Q = [0]
while Q:
  q = Q.pop(0)
  for adj in E[q]:
    if D[adj] >= 0:
      continue
    D[adj] = D[q] + 1
    C[adj] += C[q]
    Q.append(adj)
print((' '.join([str(c) for c in C])))

# Optimized solution
N, Q = list(map(int, input().split()))
E = [[] for _ in range(N)]
C = [0] * N
C[0] = 0
for _ in range(N - 1):
  a, b = list(map(int, input().split()))
  E[a - 1].append(b - 1)
  E[b - 1].append(a - 1)
for _ in range(Q):
  p, x = list(map(int, input().split()))
  C[p - 1] += x
D = [-1] * N
D[0] = 0
Q = [0] * N
enq = 0
for pos in range(N):
  q = Q[pos]
  for adj in E[q]:
    if D[adj] >= 0:
      continue
    D[adj] = D[q] + 1
    C[adj] += C[q]
    enq += 1
    Q[enq] = adj
print((' '.join([str(c) for c in C])))
# Original solution
N,Q=list(map(int, input().split()))
node_lst=[list(map(int, input().split())) for i in range(N-1)]
ope_lst=[list(map(int, input().split())) for i in range(Q)]
cnt_lst=[0 for i in range(N)]
child_rel={}
parent_rel={}
for l in node_lst:
    src, dst = l[0], l[1]
    if src not in list(child_rel.keys()):
        child_rel[src]=[dst]
    else:
        child_rel[src].append(dst)
    if src in list(parent_rel.keys()):
        for e in parent_rel[src]:
            child_rel[e].append(dst)
    if dst not in list(parent_rel.keys()):
        parent_rel[dst]=[src]
    else:
        parent_rel[dst].append(src)
for ope in ope_lst:
    p, x = ope[0], ope[1]
    cnt_lst[p-1]+=x
    if p in list(child_rel.keys()):
        for e in child_rel[p]:
            cnt_lst[e-1]+=x
print((" ".join([str(c) for c in cnt_lst])))

# Optimized solution
N,Q=list(map(int, input().split()))
node_lst=[list(map(int, input().split())) for i in range(N-1)]
ope_lst=[list(map(int, input().split())) for i in range(Q)]
cnt_lst=[0 for i in range(N)]
for ope in ope_lst:
    p, x = ope[0], ope[1]
    cnt_lst[p-1]+=x
node_lst=sorted(node_lst, key=lambda x:x[0])
for l in node_lst:
    src, dst = l[0]-1, l[1]-1
    cnt_lst[dst]+=cnt_lst[src]
print((" ".join([str(c) for c in cnt_lst])))
# Original solution
import sys
sys.setrecursionlimit(10**7)

N, Q = list(map(int,input().split()))

# AB = [[int(x) for x in input().split()] for _ in range(N-1)]

# print(AB)

# 添字を1からにしたいのでN+1
graph = [[] for _ in range(N+1)]

# 各頂点に隣接する頂点
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)

# print(graph)
counter = [0] * (N+1)

# print(counter)

# PX = [[int(x) for x in input().split()] for _ in range(Q)]

# 各頂点に点数を足す
for _ in range(Q):
  p, x = list(map(int, input().split()))
  counter[p] += x


def shori(pa,c,val):
  val += counter[c]
  counter[c] = val
  for i in graph[c]:
    if i == pa:
      continue
    shori(c,i,val)
  
shori(0,1,0)
  

print((" ".join(map(str, counter[1:]))))




# Optimized solution
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

N, Q = list(map(int,input().split()))

# AB = [[int(x) for x in input().split()] for _ in range(N-1)]

# print(AB)

# 添字を1からにしたいのでN+1
graph = [[] for _ in range(N+1)]

# 各頂点に隣接する頂点
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)

# print(graph)
counter = [0] * (N+1)

# print(counter)

# PX = [[int(x) for x in input().split()] for _ in range(Q)]

# 各頂点に点数を足す
for _ in range(Q):
  p, x = list(map(int, input().split()))
  counter[p] += x


def shori(pa,c,val):
  val += counter[c]
  counter[c] = val
  for i in graph[c]:
    if i == pa:
      continue
    shori(c,i,val)
  
shori(0,1,0)
  

print((" ".join(map(str, counter[1:]))))
# Original solution
N,Q = list(map(int,input().split()))
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = list(map(int,input().split()))
    edges[a].append(b)
    edges[b].append(a)

add = [0]*(N+1)
for i in range(Q):
    p,x = list(map(int,input().split()))
    add[p] += x

stack = [(1,0)]
ans = [0]*(N+1)
not_checked = [True]*(N+1)
while stack:
    v,cnt = stack.pop()
    ans[v] = cnt+add[v]
    not_checked[v] = False
    for edge in edges[v]:
        if not_checked[edge]:
            stack.append((edge,ans[v]))

for i in range(1,N):
    print(ans[i],end=" ")
print(ans[N])


# Optimized solution
def main():
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

    add = [0]*(N+1)
    for i in range(Q):
        p,x = list(map(int,input().split()))
        add[p] += x

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

    for i in range(1,N):
        print(ans[i],end=" ")
    print(ans[N])

if __name__ == "__main__":
    main()
# Original solution
def main():
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

    add = [0]*(N+1)
    for i in range(Q):
        p,x = list(map(int,input().split()))
        add[p] += x

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

    for i in range(1,N):
        print(ans[i],end=" ")
    print(ans[N])

if __name__ == "__main__":
    main()


# Optimized solution
import sys
def main():
    input = sys.stdin.readline
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

    add = [0]*(N+1)
    for i in range(Q):
        p,x = list(map(int,input().split()))
        add[p] += x

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

    for i in range(1,N):
        print(ans[i],end=" ")
    print(ans[N])

if __name__ == "__main__":
    main()
# Original solution
import sys

sys.setrecursionlimit(10 ** 6)

class Node(object):
    def __init__(self):
        self.value = 0
        self.children_id = []

    def set_child(self, child_id):
        self.children_id.append(child_id)

    def add_number(self, n):
        self.value += n
        for child_id in self.children_id:
            nodes[child_id].add_number(n)

    def get_value(self):
        return self.value

N, Q = map(int, sys.stdin.readline().rstrip().split())

nodes = []
for i in range(N + 1):
    nodes.append(Node())

for j in range(N - 1):
    parent, child = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].set_child(child)

for _ in range(Q):
    parent, number = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].add_number(number)

res = []
for k in range(1, N + 1):
    res.append(nodes[k].get_value())

print(*res, sep=' ')


# Optimized solution
N, Q = map(int, input().split())

nodes = [0 for _ in range(N + 1)]

branches = []
for j in range(N - 1):
    parent, child = map(int, input().split())
    branches.append([parent, child])

for _ in range(Q):
    parent, number = map(int, input().split())
    nodes[parent] += number

branches.sort()

for branch in branches:
    parent = branch[0]
    child = branch[1]
    nodes[child] += nodes[parent]

print(*nodes[1:], sep=' ')
# Original solution
import sys
sys.setrecursionlimit(1000000)


n,q=list(map(int,input().split()))
ki=[[] for i in range(n+1)]
ki[0]="null"
 
for i in range(n-1):
    a,b=list(map(int,input().split()))
    ki[a].append(b)
    ki[b].append(a)
 
scores=[0 for i in range(n+1)]
scores[0]="null"
for i in range(q):
    p,x=list(map(int,input().split()))
    scores[p]+=x
 
 
ans=[0 for i in range(n+1)]
ans[0]="null"
point=0

ed=[]
 
def tansa(n,point):
    ed.append(n)
    point+=scores[n]
    for p in ki[n]:
        if not p in ed:
            tansa(p,point)
    else:
        ans[n]=point
        
tansa(1,0)
 
ans=ans[1:]
ans=[str(i) for i in ans]
print((" ".join(ans)))


# Optimized solution
n,q=list(map(int,input().split()))
L=[[] for i in range(n+1)]
S=[0 for i in range(n+1)]
V=[0 for i in range(n+1)]

for _ in range(n-1):
    a,b=list(map(int,input().split()))
    L[a].append(b)   
    L[b].append(a)

for _ in range(q):
    p,x=list(map(int,input().split()))
    S[p]+=x


que=[1]
head=0
V[1]=1
while len(que)>head:
    now=que[head]
    head+=1
    for nex in L[now]:
        if V[nex]==0:
            V[nex]=1
            que.append(nex)
            S[nex]+=S[now]

print((" ".join([str(i) for i in S[1:]])))
# Original solution

import sys
sys.setrecursionlimit(500000)
N, Q = list(map(int, input().split()))
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    E[a].append(b)
    E[b].append(a)
C = [0] * (N+1)
for _ in range(Q):
    p, x = list(map(int, input().split()))
    C[p] += x

Ans = [0] * (N+1)
def dfs(v, p, a):
    global ans
    a += C[v]
    Ans[v] = a
    for u in E[v]:
        if u!=p:
            dfs(u, v, a)
dfs(1, 0, 0)
print((" ".join(map(str, Ans[1:]))))


# Optimized solution
import sys
input = sys.stdin.readline

import sys
sys.setrecursionlimit(500000)
N, Q = list(map(int, input().split()))
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    E[a].append(b)
    E[b].append(a)
C = [0] * (N+1)
for _ in range(Q):
    p, x = list(map(int, input().split()))
    C[p] += x
Ans = [0] * (N+1)
def dfs(v, p, a):
    a += C[v]
    Ans[v] = a
    for u in E[v]:
        if u!=p:
            dfs(u, v, a)
dfs(1, 0, 0)
print((" ".join(map(str, Ans[1:]))))
# Original solution
n,q=list(map(int,input().split()))
a=[0]*(n-1)
b=[0]*(n-1)
for i in range(n-1):
    a[i],b[i]=list(map(int,input().split()))
p=[0]*q
x=[0]*q
for k in range(q):
    p[k],x[k]=list(map(int,input().split()))
t=[[i] for i in range(1,n+1)]
for i in range(n-1):
    if a[i] not in t[a[i]-1]:
        t[a[i]-1].append(a[i])
    if b[i] not in t[a[i]-1]:
        t[a[i]-1].append(b[i])
for i in range(n):
    for j in t[i]:
        for y in t[j-1]:
            if y not in t[i]:        
                t[i].append(y)
ans=[0 for _ in range(n)]
g=0
for k in p:
    for j in t[k-1]:
        ans[j-1]+=x[g]
    g+=1  
print((' '.join(map(str,ans))))


# Optimized solution
import sys
input = sys.stdin.readline
n,q=list(map(int,input().split()))
a=[[0,0] for _ in range(n-1)]
for i in range(n-1):
    a[i][0],a[i][1]=list(map(int,input().split()))
a.sort()
p=[[0,0] for _ in range(q)]
for k in range(q):
    p[k][0],p[k][1]=list(map(int,input().split()))
p.sort()
t=[[i] for i in range(1,n+1)]
ans=[0 for _ in range(n)]
for i in range(q):
    ans[p[i][0]-1]+=p[i][1]
for i in range(n-1):
    ans[a[i][1]-1]+=ans[a[i][0]-1]  
print((' '.join(map(str,ans))))
# Original solution
import collections
N,Q=map(int,input().split())
lc=[[] for i in range(N)]#二重リストで木を表現
for i in range(N-1):
    a,b=map(int,input().split())
    lc[a-1].append(b-1)
    lc[b-1].append(a-1)
lv=[0 for i in range(N)]#値のリスト
for i in range(Q):
    p,x=map(int,input().split())
    lv[p-1]+=x
lf=[0 for i in range(N)]#訪れたかどうか
#d=collections.deque([0])
#lp=[0]
lp=collections.deque([0])
lf[0]=1
#for i in range(N):
while len(lp)>0:
    #p=lp[-1]
    p=lp.pop()
    for c in lc[p]:
        if lf[c]==0:
            lv[c]+=lv[p]
            lf[c]=1
            lp.append(c)
for i in range(N-1):
    print(lv[i],end=" ")
print(lv[N-1])


# Optimized solution
import collections
N,Q=map(int,input().split())
lc=[[] for i in range(N)]#二重リストで木を表現
for i in range(N-1):
    a,b=map(int,input().split())
    lc[a-1].append(b-1)
    lc[b-1].append(a-1)
lv=[0 for i in range(N)]#値のリスト
for i in range(Q):
    p,x=map(int,input().split())
    lv[p-1]+=x
lf=[0 for i in range(N)]#訪れたかどうか
#d=collections.deque([0])
#lp=[0]
lp=collections.deque([0])
lf[0]=1
#for i in range(N):
while len(lp)>0:
    #p=lp[-1]
    #p=lp.pop()
    p=lp.popleft()
    for c in lc[p]:
        if lf[c]==0:
            lv[c]+=lv[p]
            lf[c]=1
            lp.append(c)
for i in range(N-1):
    print(lv[i],end=" ")
print(lv[N-1])
#スタックだとリストかデキューかは関係ない
# Original solution
N,Q=list(map(int,input().split()))

ans=[0]*N
ab=[[] for i in range(N)]

for _ in range(N-1):
    a,b=list(map(int,input().split()))
    ab[a-1].append(b-1)
    
for j,item in enumerate(ab[::-1]):
    for i in item:
        ab[N-j-1].extend(ab[i])

#for i in range(N):
#    ab[i]=list(set(ab[i]))
    
for _ in range(Q):
    p,x=list(map(int,input().split()))
    for i in ab[p-1]:
        ans[i]=ans[i]+x
    ans[p-1]=ans[p-1]+x
#    print(ans) 

print((str(''.join(str(j)+' ' for j in ans)[:-1])))

# Optimized solution

N,Q=list(map(int,input().split()))

ans=[0]*N
ab=[[] for i in range(N)]

for _ in range(N-1):
    a,b=list(map(int,input().split()))
    ab[a-1].append(b-1)

px=[]
for _ in range(Q):
    px.append(list(map(int,input().split())))
    
    
for j,item in enumerate(ab[::-1]):
    for i in item:
        ab[N-j-1].extend(ab[i])

#for i in range(N):
#    ab[i]=list(set(ab[i]))
    
for ppxx in px:
    p,x=ppxx
    for i in ab[p-1]:
        ans[i]=ans[i]+x
    ans[p-1]=ans[p-1]+x
#    print(ans) 

print((str(''.join(str(j)+' ' for j in ans)[:-1])))
# Original solution
#!/usr/bin/env python
# coding: utf-8

# In[17]:


#from sys import stdin
#input = stdin.readline

N, Q = list(map(int, input().split()))


# In[18]:


class Node:
    def __init__(self, nb, data): #コンストラクタ
        self.nb = nb
        self.data = data #ノードがもつ数値
        self.parent = -1 # nodeがrootのとき-1、それ以外番号
        self.childs = [] # childになるnode classが入る
        
    def connect_childs(self, child_class_):
        self.childs.append(child_class_)


# In[19]:


nodes = [Node(_+1, 0) for _ in range(N)]


# In[12]:


for i in range(N-1):
    a, b = list(map(int, input().split()))
    nodes[a-1].connect_childs(nodes[b-1])
    nodes[b-1].parent = a-1


# In[13]:


for i in range(Q):
    p, x = list(map(int, input().split()))
    nodes[p-1].data += x


# In[14]:


def sum_data_to_childs(nodes):
    datas = [0]*N
    
    datas[0] = nodes[0].data
    
    for i in range(1, N):
        nodes[i].data += nodes[nodes[i].parent].data
        #print(nodes[i].data)
        datas[i] = nodes[i].data
        
    return datas


# In[15]:


datas = sum_data_to_childs(nodes)


# In[16]:


print((' '.join(map(str, datas))))


# In[ ]:






# Optimized solution
#!/usr/bin/env python
# coding: utf-8

# In[17]:


from sys import stdin
input = stdin.readline

N, Q = list(map(int, input().split()))


# In[18]:


class Node:
    def __init__(self, nb, data): #コンストラクタ
        self.nb = nb
        self.data = data #ノードがもつ数値
        self.parent = -1 # nodeがrootのとき-1、それ以外番号
        #self.childs = [] # childになるnode classが入る
        
    #def connect_childs(self, child_class_):
    #    self.childs.append(child_class_)


# In[19]:


nodes = [Node(_+1, 0) for _ in range(N)]


# In[12]:


for i in range(N-1):
    a, b = list(map(int, input().split()))
    #nodes[a-1].connect_childs(nodes[b-1])
    nodes[b-1].parent = a-1


# In[13]:


for i in range(Q):
    p, x = list(map(int, input().split()))
    nodes[p-1].data += x


# In[14]:


def sum_data_to_childs(nodes):
    datas = [0]*N
    
    datas[0] = nodes[0].data
    
    for i in range(1, N):
        nodes[i].data += nodes[nodes[i].parent].data
        #print(nodes[i].data)
        datas[i] = nodes[i].data
        
    return datas


# In[15]:


datas = sum_data_to_childs(nodes)


# In[16]:


print((' '.join(map(str, datas))))


# In[20]:


#datas = [0] * N


# In[21]:


#child = [[]] * N


# In[22]:


#print(child)


# In[ ]:
# Original solution
import sys
import queue
#+++++
		
def main():
	n,q = list(map(int, input().split()))
	tree=[[] for _ in range(n+1)]
	hh=[ 0 for _ in range(n+1)]
	ret=[0 for _ in range(n+1)]
	
	for i in range(n-1):
		pa,ch = list(map(int, input().split()))
		tree[pa].append(ch)
		
	for v in range(q):
		nd, hv = list(map(int, input().split()))
		hh[nd] += hv
		
	ol = queue.Queue(n+1)
	ret[1]=hh[1]
	vv=hh[1]
	for cc in tree[1]:
		ol.put((vv,cc))
		
	while not ol.empty():
		ph,nd=ol.get()
		ret[nd]=hh[nd]+ph
		vv=ret[nd]
		for cc in tree[nd]:
			ol.put((vv,cc))

	print((' '.join([str(v) for v in ret[1:]])))
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

# Optimized solution
import sys
import queue
#+++++
		
def main():
	n,q = list(map(int, input().split()))
	tree=[[] for _ in range(n+1)]
	hh=[0 for _ in range(n+1)]
	ret=[0 for _ in range(n+1)]
	
	for i in range(n-1):
		pa,ch = list(map(int, input().split()))
		tree[pa].append(ch)
		
	for v in range(q):
		nd, hv = list(map(int, input().split()))
		hh[nd] += hv
		
	ol = queue.Queue(n+1)
	ret[1]=hh[1]
	vv=hh[1]
	for cc in tree[1]:
		ol.put((vv,cc))
		
	while not ol.empty():
		ph,nd=ol.get()
		ret[nd]=hh[nd]+ph
		vv=ret[nd]
		for cc in tree[nd]:
			ol.put((vv,cc))

	rets=' '.join([str(v) for v in ret[1:]])
	print(rets)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
# Original solution

a,b=map(int,input().split())
y=[]
for i in range(a-1):
    v=list(map(int,input().split()))
    y.append(v)
y.sort(key=lambda net:net[0])
ans=[0]*a
for j in range(b):
    c,d=map(int,input().split())
    ans[c-1]=ans[c-1]+d
for k in range(a-1):
    yy=y[k][0]-1
    zz=y[k][1]-1
    ans[zz]=ans[zz]+ans[yy]
print(*ans,sep=" ")


# Optimized solution
a,b=map(int,input().split())
y=[]
for i in range(a-1):
    v=list(map(int,input().split()))
    y.append(v)
y.sort(key=lambda n:n[0])
ans=[0]*a
for j in range(b):
    c,d=map(int,input().split())
    ans[c-1]=ans[c-1]+d
for k in range(a-1):
    ans[y[k][1]-1]=ans[y[k][1]-1]+ans[y[k][0]-1]
print(*ans,sep=" ")
# Original solution
N, Q = map(int, input().split())

to = [[] for _ in range(N)]
for _ in range(N - 1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  to[a].append(b)
  to[b].append(a)

queue = [0]
branch = [[i] for i in range(N)]
parent = [[] for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    branch[q].append(br)
    to[br].remove(q)
    parent[br].append(q)
    for p in parent[q]:
      parent[br].append(p)
    queue.append(br)

for i in range(1, N):
  for p in parent[i]:
    if not i in branch[p]:
      branch[p].append(i)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  for b in branch[p]:
    cnt[b] += x

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")


# Optimized solution
N, Q = map(int, input().split())

to = [[] for _ in range(N)]
for _ in range(N - 1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  to[a].append(b)
  to[b].append(a)

queue = [0]
parent = [[] for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    to[br].remove(q)
    parent[br].append(q)
    queue.append(br)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [0]
while len(queue) > 0:
  q = queue.pop(0)
  if q != 0:
    cnt[q] += cnt[parent[q][0]]
  for br in to[q]:
    queue.append(br)

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")
# Original solution
from collections import deque
n, q = list(map(int, input().split()))

edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = list(map(int, input().split()))
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

imos = [0] * n
for i in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    imos[p] += x

q = deque([(0, -1)])
while q:
    v, p = q.pop()
    for u in edge[v]:
        if u == p:
            continue
        imos[u] += imos[v]
        q.append((u, v))

print((' '.join([str(x) for x in imos])))


# Optimized solution
import sys
from collections import deque
input = sys.stdin.readline
n, q = list(map(int, input().split()))

edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = list(map(int, input().split()))
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

imos = [0] * n
for i in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    imos[p] += x

q = deque([(0, -1)])
while q:
    v, p = q.pop()
    for u in edge[v]:
        if u == p:
            continue
        imos[u] += imos[v]
        q.append((u, v))

print((' '.join([str(x) for x in imos])))