import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from copy import deepcopy

from collections import deque

def main():

    N, Q = map(int, readline().split())

    m = map(int, read().split())

    n = deepcopy(m)

    to = [[] for _ in range(N)]

    for a, b in [(a-1, b-1) for a, b in zip(m, m)][:N-1]:

        to[a].append(b)

        to[b].append(a)

    score = [0 for _ in range(N)]

    for p, x in [(p-1, x) for p, x in zip(n, n)][N-1:]:

        score[p] += x



    dq = deque()

    dq.append(0)

    done = [0 for _ in range(N)]

    done[0] = 1

    while len(dq)>0:

        node = dq.popleft()

        for nx in to[node]: 

            if done[nx] == 1:

                continue 

            done[nx] = 1

            score[nx] += score[node]

            dq.append(nx)

    for i in score:

        print(i, end=' ')

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from collections import deque 

def main():

    N, Q = map(int, readline().split())

    to = [[] for _ in range(N)]

    for _ in range(N-1):

        a, b = map(int, readline().split())

        a -= 1

        b -= 1

        to[a].append(b)

        to[b].append(a)

    score = [0 for  _ in range(N)]

    for _ in range(Q):

        p, x = map(int, readline().split()) 

        p -= 1

        score[p] += x  

    

    dq = deque() 

    dq.append(0)

    done = [0 for _ in range(N)]

    done[0] = 1



    while len(dq)>0:

        v = dq.popleft()

        for nx in to[v]:

            if done[nx]:

                continue

            score[nx] += score[v]

            done[nx] = 1

            dq.append(nx)

    for i in range(N):

        if i==N-1:

            print(score[i])

        else:

            print(score[i], end=' ')

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from copy import deepcopy
from collections import deque


def main():
    N, Q = map(int, readline().split())
    m = map(int, read().split())
    n = deepcopy(m)
    to = [[] for _ in range(N)]
    for a, b in [(a - 1, b - 1) for a, b in zip(m, m)][: N - 1]:
        to[a].append(b)
        to[b].append(a)
    score = [0 for _ in range(N)]
    for p, x in [(p - 1, x) for p, x in zip(n, n)][N - 1 :]:
        score[p] += x
    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    while len(dq) > 0:
        node = dq.popleft()
        for nx in to[node]:
            if done[nx] == 1:
                continue
            done[nx] = 1
            score[nx] += score[node]
            dq.append(nx)
    for i in score:
        print(i, end=" ")


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


def main():
    N, Q = map(int, readline().split())
    to = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, readline().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
    score = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        score[p] += x
    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    while len(dq) > 0:
        v = dq.popleft()
        for nx in to[v]:
            if done[nx]:
                continue
            score[nx] += score[v]
            done[nx] = 1
            dq.append(nx)
    for i in range(N):
        if i == N - 1:
            print(score[i])
        else:
            print(score[i], end=" ")


if __name__ == "__main__":
    main()

-from copy import deepcopy -    m = map(int, read().split()) -    n = deepcopy(m) -    for a, b in [(a - 1, b - 1) for a, b in zip(m, m)][: N - 1]: +    for _ in range(N - 1): +        a, b = map(int, readline().split()) +        a -= 1 +        b -= 1 -    for p, x in [(p - 1, x) for p, x in zip(n, n)][N - 1 :]: +    for _ in range(Q): +        p, x = map(int, readline().split()) +        p -= 1 -        node = dq.popleft() -        for nx in to[node]: -            if done[nx] == 1: +        v = dq.popleft() +        for nx in to[v]: +            if done[nx]: +            score[nx] += score[v] -            score[nx] += score[node] -    for i in score: -        print(i, end=" ") +    for i in range(N): +        if i == N - 1: +            print(score[i]) +        else: +            print(score[i], end=" ")