import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7





def main():

	N, Q = MAP()

	ab = [LIST() for _ in range(N-1)]

	px = [LIST() for _ in range(Q)]



	graph = defaultdict(list)



	for a, b in ab:

		graph[a-1].append(b-1)

		graph[b-1].append(a-1)



	dic = defaultdict(int)



	for p, x in px:

		dic[p-1] += x



	ans = [0]*N



	checked = [0]*N

	checked[0] = 1



	q = deque([])

	q.append(0)

	

	while q:

		n = q.popleft()

		ans[n] += dic[n]

		for node in graph[n]:

			if checked[node]:

				continue

			ans[node] += ans[n]

			checked[node] = 1

			q.append(node)



	print((*ans))



if __name__ == '__main__':

	main()

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7





N, Q = MAP()

ab = [LIST() for _ in range(N-1)]

px = [LIST() for _ in range(Q)]



graph = defaultdict(list)



for a, b in ab:

	graph[a-1].append(b-1)

	graph[b-1].append(a-1)



dic = defaultdict(int)



for p, x in px:

	dic[p-1] += x



check = [0]*N

check[0] = 1



ans = [0]*N



q = deque([0])



while q:

	n = q.popleft()

	ans[n] += dic[n]

	for node in graph[n]:

		if check[node]:

			continue

		ans[node] += ans[n]

		check[node] = 1

		q.append(node)



print((*ans))





import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
)  # , log2
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7


def main():
    N, Q = MAP()
    ab = [LIST() for _ in range(N - 1)]
    px = [LIST() for _ in range(Q)]
    graph = defaultdict(list)
    for a, b in ab:
        graph[a - 1].append(b - 1)
        graph[b - 1].append(a - 1)
    dic = defaultdict(int)
    for p, x in px:
        dic[p - 1] += x
    ans = [0] * N
    checked = [0] * N
    checked[0] = 1
    q = deque([])
    q.append(0)
    while q:
        n = q.popleft()
        ans[n] += dic[n]
        for node in graph[n]:
            if checked[node]:
                continue
            ans[node] += ans[n]
            checked[node] = 1
            q.append(node)
    print((*ans))


if __name__ == "__main__":
    main()

import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
)  # , log2
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, Q = MAP()
ab = [LIST() for _ in range(N - 1)]
px = [LIST() for _ in range(Q)]
graph = defaultdict(list)
for a, b in ab:
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
dic = defaultdict(int)
for p, x in px:
    dic[p - 1] += x
check = [0] * N
check[0] = 1
ans = [0] * N
q = deque([0])
while q:
    n = q.popleft()
    ans[n] += dic[n]
    for node in graph[n]:
        if check[node]:
            continue
        ans[node] += ans[n]
        check[node] = 1
        q.append(node)
print((*ans))

- - -def main(): -    N, Q = MAP() -    ab = [LIST() for _ in range(N - 1)] -    px = [LIST() for _ in range(Q)] -    graph = defaultdict(list) -    for a, b in ab: -        graph[a - 1].append(b - 1) -        graph[b - 1].append(a - 1) -    dic = defaultdict(int) -    for p, x in px: -        dic[p - 1] += x -    ans = [0] * N -    checked = [0] * N -    checked[0] = 1 -    q = deque([]) -    q.append(0) -    while q: -        n = q.popleft() -        ans[n] += dic[n] -        for node in graph[n]: -            if checked[node]: -                continue -            ans[node] += ans[n] -            checked[node] = 1 -            q.append(node) -    print((*ans)) - - -if __name__ == "__main__": -    main() +N, Q = MAP() +ab = [LIST() for _ in range(N - 1)] +px = [LIST() for _ in range(Q)] +graph = defaultdict(list) +for a, b in ab: +    graph[a - 1].append(b - 1) +    graph[b - 1].append(a - 1) +dic = defaultdict(int) +for p, x in px: +    dic[p - 1] += x +check = [0] * N +check[0] = 1 +ans = [0] * N +q = deque([0]) +while q: +    n = q.popleft() +    ans[n] += dic[n] +    for node in graph[n]: +        if check[node]: +            continue +        ans[node] += ans[n] +        check[node] = 1 +        q.append(node) +print((*ans))