(n,q),*t=[list(map(int,t.split()))for t in open(0)]

s=[0]

d=s*n

f=s*n

e=[[]for _ in d]

for t in t:

 a,b=t

 if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,

 else:d[a-1]+=b

while s:

 v=s.pop();f[v]=-1

 for w in e[v]:

  if~f[w]:d[w]+=d[v];s+=w,

print((*d))
(n,q),*t=[list(map(int,t.split()))for t in open(0)]

s=[0]

d=s*n

f=s*n

e=[[]for _ in d]

for a,b in t:

 if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,

 else:d[a-1]+=b

while s:

 v=s.pop();f[v]=-1

 for w in e[v]:

  if~f[w]:d[w]+=d[v];s+=w,

print((*d))
(n, q), *t = [list(map(int, t.split())) for t in open(0)]
s = [0]
d = s * n
f = s * n
e = [[] for _ in d]
for t in t:
    a, b = t
    if ~-n:
        n -= 1
        e[a - 1] += (b - 1,)
        e[b - 1] += (a - 1,)
    else:
        d[a - 1] += b
while s:
    v = s.pop()
    f[v] = -1
    for w in e[v]:
        if ~f[w]:
            d[w] += d[v]
            s += (w,)
print((*d))

(n, q), *t = [list(map(int, t.split())) for t in open(0)]
s = [0]
d = s * n
f = s * n
e = [[] for _ in d]
for a, b in t:
    if ~-n:
        n -= 1
        e[a - 1] += (b - 1,)
        e[b - 1] += (a - 1,)
    else:
        d[a - 1] += b
while s:
    v = s.pop()
    f[v] = -1
    for w in e[v]:
        if ~f[w]:
            d[w] += d[v]
            s += (w,)
print((*d))

-for t in t: -    a, b = t +for a, b in t: