CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque
n, q = list(map(int, input().split()))
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = list(map(int, input().split()))
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = list(map(int, input().split()))
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  t = m[i]
  ans[i]+=j
  for r in range(t+1,len(kyori)):
    for z in kyori[r]:
      ans[z]+=j
print((' '.join(map(str,ans))))

# Optimized solution
from collections import deque
n, q = list(map(int, input().split()))
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = list(map(int, input().split()))
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = list(map(int, input().split()))
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
m1 = [-1]*n
m1[0] = 0
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
    if m1[i] == -1:
      m1[i] = d
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  ans[i]+=j
for i in kyori[1:]:
  for j in i:
    ans[j] = ans[j] + ans[m1[j]]
print((' '.join(map(str,ans))))
# Original solution
from collections import deque
n, q = list(map(int, input().split()))
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = list(map(int, input().split()))
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = list(map(int, input().split()))
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
m1 = [-1]*n
m1[0] = 0
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
    if m1[i] == -1:
      m1[i] = d
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  ans[i]+=j
for i in kyori[1:]:
  for j in i:
    ans[j] = ans[j] + ans[m1[j]]
print((' '.join(map(str,ans))))

# Optimized solution
from collections import deque
n, q = list(map(int, input().split()))
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = list(map(int, input().split()))
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = list(map(int, input().split()))
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
m1 = [-1]*n
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
      m1[i] = d
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  ans[i]+=j
for i in kyori[1:]:
  for j in i:
    ans[j] = ans[j] + ans[m1[j]]
print((' '.join(map(str,ans))))
# Original solution
N,Q=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(N-1)]
PX=[list(map(int,input().split())) for i in range(Q)]

eda=[[] for i in range(N+1)]

pt= [0 for i in range(N+1)]
for a,b in AB:
    eda[a].append(b)
    eda[b].append(a)
for p,x in PX:
    pt[p]+=x
eda=[sorted(i) for i in eda]

stack=[[1,eda[1]]]
v=set()
v.add(1)
while stack:
    while stack[-1][1]:
        a=stack[-1][1].pop()
        if not a in v:
            v.add(a)
            pt[a]+=pt[stack[-1][0]]
            stack.append([a,eda[a]])
    stack.pop()
print((" ".join(list(map(str,pt[1:])))))


# Optimized solution
N,Q=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(N-1)]
PX=[list(map(int,input().split())) for i in range(Q)]

eda=[[] for i in range(N+1)]

pt= [0 for i in range(N+1)]
for a,b in AB:
    eda[a].append(b)
    eda[b].append(a)
for p,x in PX:
    pt[p]+=x


stack=[[1,eda[1]]]
v=set()
v.add(1)
while stack:
    while stack[-1][1]:
        a=stack[-1][1].pop()
        if not a in v:
            v.add(a)
            pt[a]+=pt[stack[-1][0]]
            stack.append([a,eda[a]])
    stack.pop()
print((" ".join(list(map(str,pt[1:])))))
# Original solution
class Node:
  def __init__(self):
    self.counter = 0
    self.childs = []
    self.parents = set()
  def add_child(self, node):
    self.childs.append(node)
  def add_parents(self, node):
    self.parents.add(node)

N, Q = [int(i) for i in input().split()]
ndic = {}
for i in range(1, N+1):
  ndic[i] = Node()
  ndic[i].add_child(ndic[i])
for i in range(N-1):
  a, b = [int(i) for i in input().split()]
  ndic[a].add_child(ndic[b])
  ndic[b].add_parents(ndic[a])
  for n in ndic[a].parents:
    n.add_child(ndic[b])  
    ndic[b].add_parents(n)

from collections import defaultdict
adddict = defaultdict(int)
for i in range(Q):
  p, x = [int(i) for i in input().split()]
  adddict[p] += x
for k, v in list(adddict.items()):
  if v > 0:
    for j in ndic[k].childs:
      j.counter += v
ans = ""
for k, v in list(ndic.items()):
  ans += str(v.counter) + " "
print((ans[:-1]))

# Optimized solution
n, q = list(map(int, input().split()))
 
tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = list(map(int, input().split()))
    tree[a].append(b)
    tree[b].append(a)
 
cnt = [0]*n
for _ in range(q):
    p, x = list(map(int, input().split()))
    cnt[p-1] += x
 
check = [0]*n
 
tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)
 
 
print((" ".join(map(str, cnt))))
# Original solution
# ABC138D

import sys
sys.setrecursionlimit(1000000000)
def dfs(kol,adj,v,p):
    for nv in adj[v]:
        if nv==p:
            continue
        else:
            dfs(kol,adj,nv,v)
    kol[v]+=[v]
    if p!=-1:
        kol[p]+=kol[v]
N,Q=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    adj[a-1]+=[b-1]
    adj[b-1]+=[a-1]
    
ct=[0]*N
kol=[[] for i in range(N)]

dfs(kol,adj,0,-1)

for i in range(Q):
    p,x=map(int,input().split())
    for j in kol[p-1]:
        ct[j]+=x

print(ct[0], end="")
for i in range(1,N):
    print(" {}".format(ct[i]),end="")
print("")


# Optimized solution
# ABC138D

import sys
sys.setrecursionlimit(1000000000)

def dfs(adj,v,p,px,x,ct):
    x+=px[v]
    for nv in adj[v]:
        if nv==p:
            continue
        else:
            dfs(adj,nv,v,px,x,ct)
    ct[v]+=x

N,Q=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    adj[a-1]+=[b-1]
    adj[b-1]+=[a-1]
px=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    px[p-1]+=x
    
ct=[0]*N
dfs(adj,0,-1,px,0,ct)


print(ct[0], end="")
for i in range(1,N):
    print(" {}".format(ct[i]),end="")
print("")
# Original solution
# ABC138D

import sys
sys.setrecursionlimit(1000000000)

def dfs(adj,v,p,px,x,ct):
    x+=px[v]
    for nv in adj[v]:
        if nv==p:
            continue
        else:
            dfs(adj,nv,v,px,x,ct)
    ct[v]+=x

N,Q=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    adj[a-1]+=[b-1]
    adj[b-1]+=[a-1]
px=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    px[p-1]+=x
    
ct=[0]*N
dfs(adj,0,-1,px,0,ct)


print(ct[0], end="")
for i in range(1,N):
    print(" {}".format(ct[i]),end="")
print("")


# Optimized solution
# ABC138D

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000000)

def dfs(adj,v,p,px,x,ct):
    x+=px[v]
    for nv in adj[v]:
        if nv==p:
            continue
        else:
            dfs(adj,nv,v,px,x,ct)
    ct[v]+=x

def main():
    N,Q=map(int,input().split())
    adj=[[] for i in range(N)]
    for i in range(N-1):
        a,b=map(int,input().split())
        adj[a-1]+=[b-1]
        adj[b-1]+=[a-1]
    px=[0]*N
    for i in range(Q):
        p,x=map(int,input().split())
        px[p-1]+=x
        
    ct=[0]*N
    dfs(adj,0,-1,px,0,ct)
    
    
    print(ct[0], end="")
    for i in range(1,N):
        print(" {}".format(ct[i]),end="")
    print("")
    
if __name__=="__main__":
    main()
# Original solution
import sys
sys.setrecursionlimit(10**7)

def main():
    N, Q = [int(i) for i in input().split()]
    V = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        V[a].add(b)
        V[b].add(a)
    C = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        C[p - 1] += x
    cur = [(0, 0)]
    while cur:
        nxt = []
        for n, x in cur:
            C[n] = x = C[n] + x
            for c in V[n]:
                V[c].remove(n)
                nxt.append((c, x))
        cur = nxt
    print((' '.join(str(c) for c in C)))

main()


# Optimized solution
def main():
    N, Q = [int(i) for i in input().split()]
    V = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        V[a].add(b)
        V[b].add(a)
    C = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        C[p - 1] += x
    cur = [(0, 0)]
    while cur:
        n, x = cur.pop()
        C[n] = x = C[n] + x
        for c in V[n]:
            V[c].remove(n)
            cur.append((c, x))
    print((' '.join(str(c) for c in C)))

main()
# Original solution
def main():
    N, Q = [int(i) for i in input().split()]
    V = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        V[a].add(b)
        V[b].add(a)
    C = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        C[p - 1] += x
    cur = [(0, 0)]
    while cur:
        n, x = cur.pop()
        C[n] = x = C[n] + x
        for c in V[n]:
            V[c].remove(n)
            cur.append((c, x))
    print((' '.join(str(c) for c in C)))

main()


# Optimized solution
def main():
    N, Q = [int(i) for i in input().split()]
    V = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        V[a].append(b)
        V[b].append(a)
    C = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        C[p - 1] += x
    cur = [(0, 0, -1)]
    while cur:
        n, x, f = cur.pop()
        C[n] = x = C[n] + x
        for c in V[n]:
            if c != f:
                cur.append((c, x, n))
    print((' '.join(str(c) for c in C)))

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

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

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


def dfs(n, pre):
    for nxt in G[n]:
        if nxt == pre:
            continue
        val[nxt] += val[n]
        dfs(nxt, n)


dfs(0, 0)

answer = ' '.join(map(str, val[:]))
print(answer)


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

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

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

used = [False]*N


def dfs(s):
    stack = []
    stack.append(s)
    while len(stack) > 0:
        now = stack[-1]
        used[now] = True
        stack.pop()
        for nxt in G[now]:
            if used[nxt]:
                continue
            val[nxt] += val[now]
            stack.append(nxt)


dfs(0)

answer = ' '.join(map(str, val[:]))
print(answer)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

used = [False]*N


def dfs(s):
    stack = []
    stack.append(s)
    while len(stack) > 0:
        now = stack[-1]
        used[now] = True
        stack.pop()
        for nxt in G[now]:
            if used[nxt]:
                continue
            val[nxt] += val[now]
            stack.append(nxt)


dfs(0)

answer = ' '.join(map(str, val[:]))
print(answer)


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

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

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

used = [False]*N


def dfs(s):
    stack = []
    stack.append(s)
    while len(stack) > 0:
        now = stack[-1]
        used[now] = True
        stack.pop()
        for nxt in G[now]:
            if used[nxt]:
                continue
            val[nxt] += val[now]
            stack.append(nxt)


dfs(0)

answer = ' '.join(map(str, val[:]))
print(answer)
# Original solution
import sys
input = sys.stdin.readline

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

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

used = [False]*N


def dfs(s):
    stack = []
    stack.append(s)
    while len(stack) > 0:
        now = stack[-1]
        used[now] = True
        stack.pop()
        for nxt in G[now]:
            if used[nxt]:
                continue
            val[nxt] += val[now]
            stack.append(nxt)


dfs(0)

answer = ' '.join(map(str, val[:]))
print(answer)


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

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

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


def dfs(s):
    used = [False]*N
    stack = []
    stack.append(s)
    while len(stack):
        now = stack[-1]
        used[now] = True
        stack.pop()
        for nxt in G[now]:
            if used[nxt]:
                continue
            val[nxt] += val[now]
            stack.append(nxt)

dfs(0)

answer = ' '.join(map(str, val[:]))
print(answer)
# Original solution
import sys
input = sys.stdin.readline #入力行数が多いから高速化が必要
sys.setrecursionlimit(int(1E+7))
#小さすぎるデフォルト値を変え再起処理の上限を引き上げる(だいたい1000やから)
def main():
    n ,q = list(map(int,input().split()))
    link = [[]  for i in range(n + 1)]
    for  i in range(n - 1):
        a,b = list(map(int,input().split()))
        link[a].append(b)
        link[b].append(a)
    #print(link)
    V = [0] * (n + 1)
    for j in range(q):
        p, x = list(map(int,input().split()))
        V[p] += x
    #print(V)

    def dfs(i, parent, acc): #深さ優先探索なり
        V[i] += acc #親ノードまでの累積値を加算
        for j in link[i]:
            if j != parent: # 親ノードを追加しない
                dfs(j, i, V[i])

    cur = 1
    parent = 0
    acc = 0
    dfs(cur, parent, acc) #親ノードを０としてスタート
    V = [str(i) for i in V]
    print((" ".join(V[1:])))#数字はjoinつかえないので

if __name__ == "__main__":
    main()


# Optimized solution
#<D>
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
def main():
    N, Q = list(map(int ,input().split()))
    link = [[] for n in range(N + 1)]
    for n in range(N - 1):
        a, b = list(map(int, input().split()))
        link[a].append(b)
        link[b].append(a)
    V = [0] * (N + 1)
    for q in range(Q):
        p, x = list(map(int, input().split()))
        V[p] += x
    def dfs(i, parent, acc):
        V[i] += acc
        for j in link[i]:
            if j != parent:
                dfs(j, i, V[i])

    cur = 1
    parent = 0
    acc = 0
    dfs(cur, parent, acc)
    V = [str(i) for i in V]
    print((" ".join(V[1:])))

if __name__ == "__main__":
    main()
# Original solution
from collections import deque
import sys
sys.setrecursionlimit(10**7)

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

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

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

def dfs(v, p):
    if p != -1:
        count[v] += count[p]
    for next_v in G[v]:
        if next_v == p: continue
        dfs(next_v, v)

dfs(0, -1)
print((" ".join(map(str, count))))

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

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

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

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

def dfs(v, p):
    if p != -1:
        count[v] += count[p]
    for next_v in G[v]:
        if next_v == p: continue
        dfs(next_v, v)

dfs(0, -1)
print((" ".join(map(str, count))))
# Original solution
from collections import deque

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

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

ans = [0] * (N + 1)
queue = deque()
queue.append(1)
visited = [0] * (N + 1)
visited[1] = 1
while queue:
    v = queue.pop()
    if v == 1:
        ans[v] = point[v]
    for u in adj[v]:
        if visited[u] == 0:
            queue.append(u)
            visited[u] = 1
            ans[u] = ans[v] + point[u]

print((' '.join(map(str, ans[1:]))))



# Optimized solution
from collections import deque

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

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

ans = [0] * (N + 1)
queue = deque()
queue.append(1)
visited = [0] * (N + 1)
visited[1] = 1
ans[1] = point[1]
while queue:
    v = queue.pop()
    for u in adj[v]:
        if visited[u] == 0:
            queue.appendleft(u)
            visited[u] = 1
            ans[u] = ans[v] + point[u]

print((' '.join(map(str, ans[1:]))))
# Original solution
from collections import defaultdict


def calc_parents(N, adj_nodes, root=0):
    parents = [-1 for _ in range(N)]
    frontier = [root]
    parents[root] = root
    while len(frontier) > 0:
        node = frontier.pop()
        for child in adj_nodes[node]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = node
    return parents


def sum_counts(N, parents, counter_roots):
    counter = [0 for _ in range(N)]
    for node in range(N):
        current_node = node
        parent_node = parents[current_node]
        s = counter_roots[current_node]
        while current_node != parent_node:
            current_node = parent_node
            parent_node = parents[current_node]
            s += counter_roots[current_node]
        counter[node] += s
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    parents = calc_parents(N, adj_nodes)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    counter = sum_counts(N, parents, counter_roots)
    print((' '.join(map(str, counter))))


if __name__ == '__main__':
    main()

# Optimized solution
from collections import defaultdict


def sum_counter(N, adj_nodes, counter_roots, root=0):
    parents = [-1 for _ in range(N)]
    counter = [0 for _ in range(N)]
    frontier = [root]
    counter[root] += counter_roots[root]
    parents[root] = root
    while len(frontier) > 0:
        parent = frontier.pop()
        for child in adj_nodes[parent]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = parent
            counter[child] += counter[parent] + counter_roots[child]
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    c = sum_counter(N, adj_nodes, counter_roots)
    print((' '.join(map(str, c))))


if __name__ == '__main__':
    main()
# Original solution
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N, Q = inpl()
neighbor = [[] for i in range(N)]
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    neighbor[a].append(b)
    neighbor[b].append(a)
X = [0] * N
for _ in range(Q):
    p, x = inpl()
    X[p-1] += x
result = [0] * N
def dfs(node, x, parent):
    x += X[node]
    result[node] = x
    for c in neighbor[node]:
        if c == parent:
            continue
        else:
            dfs(c,x,node)

dfs(0, 0, None)
print((' '.join(map(str,result))))

# Optimized solution
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N, Q = inpl()
neighbor = [[] for i in range(N)]
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    neighbor[a].append(b)
    neighbor[b].append(a)
X = [0] * N
for _ in range(Q):
    p, x = inpl()
    X[p-1] += x

result = [0] * N
result[0] = X[0]
visited = [False] * N
dfs_stack = [0]
x = 0
while dfs_stack:
    node = dfs_stack.pop()
    visited[node] = True
    for c in neighbor[node]:
        if visited[c]:
            continue
        else:
            dfs_stack.append(c)
            result[c] = result[node] + X[c]

print((' '.join(map(str,result))))
# Original solution
from queue import Queue

n , q = list(map(int, input().split()))
lab = []
points = [0]*n
for i in range(n-1):
    lab.append(list(map(int, input().split())))
lpx = []
for i in range(q):
    lpx.append(list(map(int, input().split())))

lll = []
for i in range(n):
    childs = Queue()
    inc = []
    parent = i+1
    childs.put(parent)
    while childs.qsize() > 0:
        a = childs.get()
        inc.append(a)
        for k in lab:
            if k[0] == a:
                childs.put(k[1])
    lll.append(list(set(inc)))

for i in lpx:
    for j in lll[i[0]-1]:
        points[j-1] += i[1]
print((' '.join(map(str, points))))


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

N,Q = list(map(int,input().split()))
aLst = [[int(x) for x in input().split()] for _ in range(N-1)]
pLst = [[int(x) for x in input().split()] for _ in range(Q)]

tmpLst = [[] for _ in range(N+1)]
for i, j in aLst:
    tmpLst[i].append(j)
    tmpLst[j].append(i)

ansLst = [0] * (N + 1)
for i,j in pLst:
    ansLst[i] += j

def dfs(v, p):
    for i in tmpLst[v]:
        if i == p:
            continue
        ansLst[i] += ansLst[v]
        dfs(i, v)


dfs(1, 0)

ans = ' '.join(map(str, ansLst[1:]))
print(ans)