import heapq as h



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

a=[0 for i in range(0,N-1)]

b=[0 for i in range(0,N-1)]

for i in range(0,N-1):

    a[i],b[i]=list(map(int,input().split()))

p=[0 for i in range(0,Q)]

x=[0 for i in range(0,Q)]

for i in range(0,Q):

    p[i],x[i]=list(map(int,input().split()))

hen=[[] for i in range(0,N+1)]

for i in range(0,N-1):

    hen[a[i]].append(b[i])

    hen[b[i]].append(a[i])

subscore=[0 for i in range(0,N+1)]

for i in range(0,Q):

    subscore[p[i]]+=x[i]



ans=[0 for i in range(0,N+1)]

flag=[0 for i in range(0,N+1)]

q=[]

q.append(1)

h.heapify(q)

sub=[]

h.heapify(sub)

while q!=[]:

    while q!=[]:

        x=h.heappop(q)

        ans[x]+=subscore[x]

        flag[x]=1

        for p in hen[x]:

            if flag[p]==0:

                h.heappush(sub,p)

                ans[p]=ans[x]

        if q==[]:

            q=sub

            sub=[]

            h.heapify(sub)

            break

ans[0]=-1

ans.remove(-1)

print((*ans))

import heapq as h

import sys



input=sys.stdin.readline



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

a=[0 for i in range(0,N-1)]

b=[0 for i in range(0,N-1)]

for i in range(0,N-1):

    a[i],b[i]=list(map(int,input().split()))

p=[0 for i in range(0,Q)]

x=[0 for i in range(0,Q)]

for i in range(0,Q):

    p[i],x[i]=list(map(int,input().split()))

hen=[[] for i in range(0,N+1)]

for i in range(0,N-1):

    hen[a[i]].append(b[i])

    hen[b[i]].append(a[i])

subscore=[0 for i in range(0,N+1)]

for i in range(0,Q):

    subscore[p[i]]+=x[i]



ans=[0 for i in range(0,N+1)]

flag=[0 for i in range(0,N+1)]

q=[]

q.append(1)

h.heapify(q)

sub=[]

h.heapify(sub)

while q!=[]:

    while q!=[]:

        x=h.heappop(q)

        ans[x]+=subscore[x]

        flag[x]=1

        for p in hen[x]:

            if flag[p]==0:

                h.heappush(sub,p)

                ans[p]=ans[x]

        if q==[]:

            q=sub

            sub=[]

            h.heapify(sub)

            break

ans[0]=-1

ans.remove(-1)

print((*ans))
import heapq as h

N, Q = list(map(int, input().split()))
a = [0 for i in range(0, N - 1)]
b = [0 for i in range(0, N - 1)]
for i in range(0, N - 1):
    a[i], b[i] = list(map(int, input().split()))
p = [0 for i in range(0, Q)]
x = [0 for i in range(0, Q)]
for i in range(0, Q):
    p[i], x[i] = list(map(int, input().split()))
hen = [[] for i in range(0, N + 1)]
for i in range(0, N - 1):
    hen[a[i]].append(b[i])
    hen[b[i]].append(a[i])
subscore = [0 for i in range(0, N + 1)]
for i in range(0, Q):
    subscore[p[i]] += x[i]
ans = [0 for i in range(0, N + 1)]
flag = [0 for i in range(0, N + 1)]
q = []
q.append(1)
h.heapify(q)
sub = []
h.heapify(sub)
while q != []:
    while q != []:
        x = h.heappop(q)
        ans[x] += subscore[x]
        flag[x] = 1
        for p in hen[x]:
            if flag[p] == 0:
                h.heappush(sub, p)
                ans[p] = ans[x]
        if q == []:
            q = sub
            sub = []
            h.heapify(sub)
            break
ans[0] = -1
ans.remove(-1)
print((*ans))

import heapq as h
import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
a = [0 for i in range(0, N - 1)]
b = [0 for i in range(0, N - 1)]
for i in range(0, N - 1):
    a[i], b[i] = list(map(int, input().split()))
p = [0 for i in range(0, Q)]
x = [0 for i in range(0, Q)]
for i in range(0, Q):
    p[i], x[i] = list(map(int, input().split()))
hen = [[] for i in range(0, N + 1)]
for i in range(0, N - 1):
    hen[a[i]].append(b[i])
    hen[b[i]].append(a[i])
subscore = [0 for i in range(0, N + 1)]
for i in range(0, Q):
    subscore[p[i]] += x[i]
ans = [0 for i in range(0, N + 1)]
flag = [0 for i in range(0, N + 1)]
q = []
q.append(1)
h.heapify(q)
sub = []
h.heapify(sub)
while q != []:
    while q != []:
        x = h.heappop(q)
        ans[x] += subscore[x]
        flag[x] = 1
        for p in hen[x]:
            if flag[p] == 0:
                h.heappush(sub, p)
                ans[p] = ans[x]
        if q == []:
            q = sub
            sub = []
            h.heapify(sub)
            break
ans[0] = -1
ans.remove(-1)
print((*ans))

+import sys +input = sys.stdin.readline