import sys

sys.setrecursionlimit(2 * 10 ** 5 + 10)



N, Q, *ABPX = list(map(int, open(0).read().split()))

AB, PX = ABPX[:2 * (N - 1)], ABPX[2 * (N - 1):]



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

for a, b in zip(*[iter(AB)] * 2):

    E[a].append(b)

    E[b].append(a)



C = [0] * (N + 1)

for p, x in zip(*[iter(PX)] * 2):

    C[p] += x





ans = [0] * (N + 1)

def dfs(v, p, acc):

    ans[v] = acc + C[v]

    for c in E[v]:

        if p != c:

            dfs(c, v, acc + C[v])



dfs(1, 0, 0)



print((*ans[1:]))
from collections import deque



N, Q, *ABPX = list(map(int, open(0).read().split()))

AB, PX = ABPX[:2 * (N - 1)], ABPX[2 * (N - 1):]



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

for a, b in zip(*[iter(AB)] * 2):

    E[a].append(b)

    E[b].append(a)



C = [0] * (N + 1)

for p, x in zip(*[iter(PX)] * 2):

    C[p] += x



ans = [0] * (N + 1)

visited = [False] * (N + 1)



Q = deque([(1, 0)])

while Q:

    v, c = Q.popleft()

    visited[v] = True



    ans[v] = c + C[v]



    for u in E[v]:

        if visited[u]:

            continue

        Q.append((u, c + C[v]))



print((*ans[1:]))
import sys

sys.setrecursionlimit(2 * 10**5 + 10)
N, Q, *ABPX = list(map(int, open(0).read().split()))
AB, PX = ABPX[: 2 * (N - 1)], ABPX[2 * (N - 1) :]
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)
C = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
    C[p] += x
ans = [0] * (N + 1)


def dfs(v, p, acc):
    ans[v] = acc + C[v]
    for c in E[v]:
        if p != c:
            dfs(c, v, acc + C[v])


dfs(1, 0, 0)
print((*ans[1:]))

from collections import deque

N, Q, *ABPX = list(map(int, open(0).read().split()))
AB, PX = ABPX[: 2 * (N - 1)], ABPX[2 * (N - 1) :]
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)
C = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
    C[p] += x
ans = [0] * (N + 1)
visited = [False] * (N + 1)
Q = deque([(1, 0)])
while Q:
    v, c = Q.popleft()
    visited[v] = True
    ans[v] = c + C[v]
    for u in E[v]:
        if visited[u]:
            continue
        Q.append((u, c + C[v]))
print((*ans[1:]))

-import sys +from collections import deque -sys.setrecursionlimit(2 * 10**5 + 10) - - -def dfs(v, p, acc): -    ans[v] = acc + C[v] -    for c in E[v]: -        if p != c: -            dfs(c, v, acc + C[v]) - - -dfs(1, 0, 0) +visited = [False] * (N + 1) +Q = deque([(1, 0)]) +while Q: +    v, c = Q.popleft() +    visited[v] = True +    ans[v] = c + C[v] +    for u in E[v]: +        if visited[u]: +            continue +        Q.append((u, c + C[v]))