CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(1000000)
s=sys.stdin.readlines()
n,q=list(map(int,s[0].split()))
G=[[]*n for i in range(n)]
P=[0]*n
V=[0]*n
R=[0]*n
for e in s[1:n]:
    a,b=list(map(int,e.split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for e in s[n:]:
    c,d=list(map(int,e.split()))
    P[c-1]+=d

def dsf(i,p):
    V[i]=1
    R[i]+=p+P[i]
    p=0
    if G[i]!=[]:
        for j in G[i]:
            if V[j]!=1:
                dsf(j,R[i])
dsf(0,0)
print((' '.join(map(str,R))))

# Optimized solution
import sys
sys.setrecursionlimit(1000000)
s=sys.stdin.readlines()
n,q=list(map(int,s[0].split()))
G=[[]*n for i in range(n)]
P=[0]*n
V=[0]*n
R=[0]*n
for e in s[1:n]:
    a,b=list(map(int,e.split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for e in s[n:]:
    c,d=list(map(int,e.split()))
    P[c-1]+=d

def dsf(i,p):
    V[i]=1
    R[i]+=p+P[i]
    p=0
    for j in G[i]:
        if V[j]!=1:
            dsf(j,R[i])
dsf(0,0)
print((' '.join(map(str,R))))
# Original solution
import sys
sys.setrecursionlimit(1000000)
s=sys.stdin.readlines()
n,q=list(map(int,s[0].split()))
G=[[]*n for i in range(n)]
P=[0]*n
V=[0]*n
R=[0]*n
for e in s[1:n]:
    a,b=list(map(int,e.split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for e in s[n:]:
    c,d=list(map(int,e.split()))
    P[c-1]+=d

def dsf(i,p):
    V[i]=1
    R[i]+=p+P[i]
    p=0
    if G[i]!=[]:
        for j in G[i]:
            if V[j]!=1:
                dsf(j,R[i])
dsf(0,0)
print((' '.join(map(str,R))))

# Optimized solution
import sys
sys.setrecursionlimit(1000000)
s=sys.stdin.readlines()
n,q=list(map(int,s[0].split()))
G=[[]*n for i in range(n)]
P=[0]*n
V=[0]*n
for e in s[1:n]:
    a,b=list(map(int,e.split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for e in s[n:]:
    c,d=list(map(int,e.split()))
    P[c-1]+=d
def dsf(i,p):
    V[i]=1
    P[i]+=p
    for j in G[i]:
        if V[j]!=1:
            dsf(j,P[i])
dsf(0,0)
print((' '.join(map(str,P))))
# Original solution
# -*- coding: utf-8 -*-

N, Q = list(map(int,input().split()))
Node = [-1] * N
Counter = [0] * N
Result = [0] * N

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

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

for i in range(N):
    p = i
    ans = 0
    while p >= 0:
        ans = ans + Counter[p]
        p = Node[p]
        
    Result[i] = ans

print((" ".join(list(map(str,Result)))))


# Optimized solution
# -*- coding: utf-8 -*-

N, Q = list(map(int,input().split()))
Node = [-1] * N
Counter = [0] * N
Result = [0] * N

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

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

for i in range(N):
    p = i
    ans = 0
    while p >= i:
        ans += Counter[p]
        p = Node[p]
    Result[i] = ans
    if p >= 0:
        Result[i] += Result[p]

print((" ".join(list(map(str,Result)))))
# Original solution

import sys
input = sys.stdin.readline

n, q = [int(x) for x in input().split()]

edge = [[] for _ in range(n)]

counter = [0] * n

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

for _ in range(q):
    a, b = [int(x) for x in input().split()]
    counter[a-1] += b

parent = [0]

for i in parent:
    for v in edge[i]:
        if v in parent:
            continue
        parent.append(v)
        counter[v] += counter[i]
        
print((" ".join(map(str, counter))))

# Optimized solution

import sys
input = sys.stdin.readline

n, q = [int(x) for x in input().split()]

edge = [[] for _ in range(n)]

counter = [0] * n

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

for _ in range(q):
    a, b = [int(x) for x in input().split()]
    counter[a-1] += b

parent = [0]
set_parent = {0}
for i in parent:
    for v in edge[i]:
        if v in set_parent:
            continue
        set_parent.add(v)
        parent.append(v)
        counter[v] += counter[i]
        
print((" ".join(map(str, counter))))
# Original solution
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(G, v, p, C):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        dfs(G, c, v, C)
        C[v].extend(C[c])


def main():
    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)

    # Give all children for each parent
    C = [[i] for i in range(N)]
    dfs(G, 0, -1, C)

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

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


if __name__ == "__main__":
    main()


# Optimized solution
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(G, v, p, point):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        point[c] += point[v]
        dfs(G, c, v, point)


def main():
    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)

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

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


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

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(G, v, p, point):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        point[c] += point[v]
        dfs(G, c, v, point)


def main():
    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)

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

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


if __name__ == "__main__":
    main()


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


def dfs(G, v, p, counter):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    counter_v = counter[v]
    for c in G[v]:
        if c == p:
            continue  # Avoid multiple access to parent
        counter[c] += counter_v
        dfs(G, c, v, counter)


def main():
    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)

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

    dfs(G, 0, -1, counter)
    # print(*counter)
    print((" ".join(map(str, counter))))


if __name__ == "__main__":
    main()
# Original solution
n,q = list(map(int,input().split()))

hen = [[0,0]]*n
for i in range(n-1) :
    hen[i] = list(map(int,input().split()))

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

y = [0]*n
for i in range(n) :
    y[i] += xlist[i]
    
    r = i
    while True :
        for j in range(n) :
            if hen[j][1] - 1 == r :
                r = hen[j][0] - 1
                y[i] += xlist[r]
                break
        if j == n-1 :
            break

c = str(y[0])
for i in range(1,n) :
    c += ' ' + str(y[i])

print(c)


# Optimized solution
n,q = list(map(int,input().split()))

hen = [[0,0]]*(n-1)
for i in range(n-1) :
    hen[i] = list(map(int,input().split()))

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

#---

hen = sorted(hen, key=lambda x:x[1])
hen = sorted(hen, key=lambda x:x[0])

for i in range(n-1) :
    xlist[hen[i][1]-1] += xlist[hen[i][0]-1]

y = xlist.copy()

c = str(y[0])
for i in range(1,n) :
    c += ' ' + str(y[i])

print(c)
# Original solution
import sys
sys.setrecursionlimit(10 ** 7)

n, q = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
px = [tuple(map(int,input().split())) for i in range(q)]

es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)


visited = [0]*n
ans = [0]*n

# DFS for tree
def dfs(v=0, parent=-1):# どこからきたかの情報を入れとく
    for to in es[v]:
        if to == parent: continue # 今回はcontinue

        if visited[to]: continue

        ans[to] += ans[v]
        dfs(to, v)


for p, x in px:
    ans[p-1] += x

dfs(0)

print(*ans, sep=' ')


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

n, q = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
px = [tuple(map(int,input().split())) for i in range(q)]

es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

ans = [0]*n

# DFS for tree (再帰はpypyの方が遅かったりするので注意)
def dfs(v=0, parent=-1):# どこからきたかの情報を入れとく
    for to in es[v]:
        if to == parent: continue # 今回はcontinue

        ans[to] += ans[v]
        dfs(to, v)


for p, x in px:
    ans[p-1] += x

dfs(0)

print(*ans, sep=' ')
# Original solution
import sys
sys.setrecursionlimit(10**7)


N, Q = list(map(int, input().split()))
G = [[] for _ in range(N)]
P = [0 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)

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


def dfs(current, parent):
    for child in G[current]:
        if child == parent:
            continue
        P[child] += P[current]
        dfs(child, current)


dfs(0, -1)

print((' '.join([str(p) for p in P])))


# Optimized solution
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion

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

v = [[] for i in range(N)]
score = [0]*N

def dfs(cur,par):
  for chi in v[cur]:
    if chi == par:
      continue
    score[chi] += score[cur]
    dfs(chi, cur)
      
for i in range(N-1):
  a, b = list(map(int, input().split()))
  a -= 1
  b -= 1
  v[a].append(b)
  v[b].append(a)

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

dfs(0,-1)
score_int=[str(a) for a in score]
output= ' '.join(score_int)
print(output)
# Original solution
import sys
sys.setrecursionlimit(10**9)
 
def dfs(now, prev):
    ans[now]+=(h[now]+ans[prev])
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        if next != prev:
            if memo[next]==True:
                # 過去に訪れていれば終わらせる
                return False
            else:
                memo[next] = True
                dfs(next, now)
 
#木構造の取り込み 
n, q = list(map(int, input().split()))
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

#操作の取り込み
h=[0]*n
for i in range(q):
    u, v = list(map(int, input().split()))
    u -= 1
    h[u]+=v

#初期のカウンター
ans=[0]*n
memo = [False for i in range(n)]

#DFSでカウンターを動かす
dfs(0,0)
 
print((' '.join(map(str, ans))))

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

def dfs(now, prev):
    ans[now]+=(h[now]+ans[prev])
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        if next != prev:
            if memo[next]==True:
                # 過去に訪れていれば終わらせる
                return False
            else:
                memo[next] = True
                dfs(next, now)
 
#木構造の取り込み 
n, q = list(map(int, input().split()))
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
 
#操作の取り込み
h=[0]*n
for i in range(q):
    u, v = list(map(int, input().split()))
    u -= 1
    h[u]+=v
 
#初期のカウンター
ans=[0]*n
memo = [False for i in range(n)]
 
#DFSでカウンターを動かす
dfs(0,0)
 
print((' '.join(map(str, ans))))
# Original solution
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def dfs(now, prev):
    ans[now]+=(h[now]+ans[prev])
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        if next != prev:
            if memo[next]==True:
                # 過去に訪れていれば終わらせる
                return False
            else:
                memo[next] = True
                dfs(next, now)
 
#木構造の取り込み 
n, q = list(map(int, input().split()))
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
 
#操作の取り込み
h=[0]*n
for i in range(q):
    u, v = list(map(int, input().split()))
    u -= 1
    h[u]+=v
 
#初期のカウンター
ans=[0]*n
memo = [False for i in range(n)]
 
#DFSでカウンターを動かす
dfs(0,0)
 
print((' '.join(map(str, ans))))

# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
 
def dfs(now, prev):
    ans[now]+=(h[now]+ans[prev])
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        if next != prev:
            dfs(next, now)
 
 
n, q = list(map(int, input().split()))
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
 
h=[0]*n
for i in range(q):
    u, v = list(map(int, input().split()))
    u -= 1
    h[u]+=v
 
ans=[0]*n
dfs(0,0)
 
print((' '.join(map(str, ans))))
# Original solution
n, q = [int(x) for x in input().split()]
vs   = []
us   = [1]
xs   = None
	
for _ in range(0, n + 1):
	vs.append([])
	xs = [0] * (n + 1)

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if v not in us:
			xs[v] += x
			us.append(v)

print((" ".join(str(x) for x in xs[1:])))


# Optimized solution
n, q = [int(x) for x in input().split()]
vs   = []
	
for _ in range(0, n + 1):
	vs.append([])
	
xs    = [0]     * (n + 1)
fs    = [False] * (n + 1)
us    = [0]     * n
fs[1] = True
us[0] = 1
ui    = 0

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if fs[v] == False:
			xs[v] += x
			ui    += 1
			us[ui] = v
			fs[v]  = True

print((" ".join(str(x) for x in xs[1:])))
# Original solution
n,q=list(map(int,input().split()))
node=[0 for i in range(n)]
tree=[]
for i in range(n-1):
    tree.append(list(map(int,input().split())))
def counter(p,x,cnt):
    for i in range(n-1):
        if tree[i][0]==p:
            if cnt[tree[i][1]-1]!=1:
                node[tree[i][1]-1]+=x
                cnt[tree[i][1]-1]=1
                counter(tree[i][1],x,cnt)
            else:
                continue
        
        
for j in range(q):
    cnt=[0 for i in range(n)]
    p,x=list(map(int,input().split()))
    cnt[p-1]=1
    node[p-1]+=x
    counter(p,x,cnt)

for i in range(n):
    node[i]=str(node[i])
print((' '.join(node)))




# Optimized solution
n,q=list(map(int,input().split()))
c=[0 for i in range(n)]
tree=sorted([list(map(int,input().split())) for i in range(n-1)])
for j in range(q):
    p,x=list(map(int,input().split()))
    c[p-1]+=x
for i in range(n-1):
    c[tree[i][1]-1]+=c[tree[i][0]-1]
for i in range(n):
    c[i]=str(c[i])
print((' '.join(c)))
# Original solution
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

import sys
sys.setrecursionlimit(100000)

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
#ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
#px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

ans = [0] * (N+1)
child = [[] for _ in range(N+1)]


def add(node, num):
    for x in child[node]:
        add(x, num)

    ans[node] += num

for a, b in [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]:
    child[a].append(b)

#print(child)

for p, x in [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]:
    ii = p
    add(p, x)

print(*ans[1:], sep=" ")


# Optimized solution
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

node_value = [0] * (N+1)
parent = [-1] * (N+1)

for a, b in ab:
    parent[b] = a

for p, x in px:
    node_value[p] += x

#print(parent)

ans = [0] * (N+1)

for i in range(1, N+1):
    ans[i] = node_value[i]
    if parent[i] != -1:
        ans[i] += ans[parent[i]]

print(*ans[1:], sep=" ")
# Original solution
import sys
sys.setrecursionlimit(10**6)
n,q = list(map(int,input().split()))
a=[[] for i in range(n)]
l=[0 for _ in range(n)]
ans=[0 for _ in range(n)]

def dfs(parent,current,value):
    value += l[current]
    ans[current] = value
    for i in a[current]:
        if i == parent:
            continue
        dfs(current,i,value)


for i in range(n-1):
    t1,t2 = list(map(int,input().split()))
    a[t1-1].append(t2-1)
    a[t2-1].append(t1-1)
    
for i in range(q):
    t1,t2 = list(map(int,input().split()))
    l[t1-1]+=t2
dfs(-1,0,0)

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

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

readline = sys.stdin.readline

n,q = list(map(int,readline().split()))
a=[[] for i in range(n)]
l=[0 for _ in range(n)]
ans=[0 for _ in range(n)]

def dfs(parent,current,value):
    value += l[current]
    ans[current] = value
    for i in a[current]:
        if i == parent:
            continue
        dfs(current,i,value)


for i in range(n-1):
    t1,t2 = list(map(int,readline().split()))
    a[t1-1].append(t2-1)
    a[t2-1].append(t1-1)
    
for i in range(q):
    t1,t2 = list(map(int,readline().split()))
    l[t1-1]+=t2
dfs(-1,0,0)

print((" ".join(map(str,ans))))
# Original solution
import sys
sys.setrecursionlimit(10**6)

readline = sys.stdin.readline

n,q = list(map(int,readline().split()))
a=[[] for i in range(n)]
l=[0 for _ in range(n)]
ans=[0 for _ in range(n)]

def dfs(parent,current,value):
    value += l[current]
    ans[current] = value
    for i in a[current]:
        if i == parent:
            continue
        dfs(current,i,value)


for i in range(n-1):
    t1,t2 = list(map(int,readline().split()))
    a[t1-1].append(t2-1)
    a[t2-1].append(t1-1)
    
for i in range(q):
    t1,t2 = list(map(int,readline().split()))
    l[t1-1]+=t2
dfs(-1,0,0)

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

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

readline = sys.stdin.readline

n,q = list(map(int,readline().split()))
a=[[] for i in range(n)]
l=[0]*n
ans=[0]*n

def dfs(parent,current,value):
    value += l[current]
    ans[current] = value
    for i in a[current]:
        if i != parent:
            dfs(current,i,value)


for i in range(n-1):
    t1,t2 = list(map(int,readline().split()))
    a[t1-1].append(t2-1)
    a[t2-1].append(t1-1)
    
for i in range(q):
    t1,t2 = list(map(int,readline().split()))
    l[t1-1]+=t2
dfs(-1,0,0)

print((" ".join(map(str,ans))))
# Original solution
from collections import deque
N,Q=map(int,input().split())
nondirtree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
rootflag=[0]*N
rootflag[0]=1
for i in range(N-1):
    a,b=map(int,input().split())
    nondirtree[a-1].append(b-1)
    nondirtree[b - 1].append(a - 1)
points=[list(map(int,input().split())) for _ in range(Q)]
#print(points)
v=0
d=deque()
d.append(v)
seen=[0]*N
seen[0]=1
score=[0]*N
while len(d)!=0:
    v=d.popleft()
    for j in nondirtree[v]:
        if seen[j]==0:
            dirtree[v].append(j)
            seen[j]=1
            d.append(j)
    #print(d,seen,dirtree)
    #input()
for i in range(Q):
    d=deque()
    v=points[i][0]-1
    d.append(v)
    while len(d)!=0:
        v=d.popleft()
        score[v]=score[v]+points[i][1]
        for j in dirtree[v]:
            d.append(j)
        #input()
print(*score,sep=" ")


# Optimized solution
from collections import deque
N,Q=map(int,input().split())
nondirtree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
rootflag=[0]*N
rootflag[0]=1
for i in range(N-1):
    a,b=map(int,input().split())
    nondirtree[a-1].append(b-1)
    nondirtree[b - 1].append(a - 1)
points=[list(map(int,input().split())) for _ in range(Q)]
#print(points)
v=0
d=deque()
d.append(v)
seen=[0]*N
seen[0]=1
score=[0]*N
ans=[0]*N
while len(d)!=0:
    v=d.popleft()
    for j in nondirtree[v]:
        if seen[j]==0:
            dirtree[v].append(j)
            seen[j]=1
            d.append(j)
    #print(d,seen,dirtree)
    #input(
#print(dirtree)
for i in range(Q):
    score[points[i][0]-1]=score[points[i][0]-1]+points[i][1]
#print(score)
v=0
d=deque()
d.append(v)
ans[0]=score[0]
while len(d)!=0:
    v=d.popleft()
    for j in dirtree[v]:
        ans[j]=ans[v]+score[j]
        d.append(j)
    #input()
    #print(ans)
print(*ans,sep=" ")
# Original solution
import itertools

while 1:
    n=int(eval(input()))
    if n==0:break
    l=[int(eval(input())) for _ in range(n)]
    print((sum([sum(sorted(l)[:len(l)-1][:i]) for i in range(1,len(l))])))



# Optimized solution
import itertools

while 1:
    n=int(eval(input()))
    if n==0:break
    l=[int(eval(input())) for _ in range(n)]
    ll=len(l)
    m=sorted(l)[:ll-1]
    print((sum([sum(m[:i]) for i in range(1,ll)])))
# Original solution
while True:
  n = int(eval(input()))
  if not n:
    break
  else:
    lst = [int(eval(input())) for _ in range(n)]
    lst.sort()
    acc = ans = 0
    for i in lst:
      ans += acc
      acc += i
    print(ans) 


# Optimized solution
while True:
  n = int(eval(input()))
  if not n:
    break
  lst = sorted([int(eval(input())) for _ in range(n)])
  print((sum([(n - i - 1) * lst[i] for i in range(n)])))
# Original solution
while 1:
	n = eval(input())
	if n == 0: break
	que = sorted([int(input()) for i in range(n)])
	print(sum([sum(que[:i]) for i in range(1,n)]))

# Optimized solution
while 1:
	n = eval(input())
	if n == 0: break
	q = sorted([int(input()) for i in range(n)])
	t = [0]*n
	for i in range(1,n):
		t[i] = t[i-1] + q[i-1]
	print(sum(t))
# Original solution
while 1:
  n=eval(input())
  if n==0: break
  x=sorted([eval(input()) for _ in [0]*n])
  s=0
  a=0
  for e in x[:-1]: a+=e; s+=a
  print(s)

# Optimized solution
while 1:
  n=eval(input())
  if n==0: break
  x=sorted([int(input()) for _ in [0]*n])
  s=0
  a=0
  for e in x[:-1]: a+=e; s+=a
  print(s)
# Original solution
while 1:
  n=int(input())
  if n==0: break
  x=sorted([int(input()) for _ in [0]*n])
  s=0
  a=0
  for e in x[:-1]: a+=e; s+=a
  print(s)

# Optimized solution
while 1:
  n=int(input())
  if n==0: break
  x=sorted(map(int,[input() for _ in [0]*n]))
  s=a=0
  for e in x[:-1]: a+=e; s+=a
  print(s)