AtCoder Beginner Contest 138 - Ki

Given is a rooted tree with N vertices numbered 1 to N.
The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.
Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.
Now, the following Q operations will be performed:
 - Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.
Find the value of the counter on each vertex after all operations.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq Q \leq 2 \times 10^5
 - 1 \leq a_i < b_i \leq N
 - 1 \leq p_j \leq N
 - 1 \leq x_j \leq 10^4
 - The given graph is a tree.
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N Q
a_1 b_1
:
a_{N-1} b_{N-1}
p_1 x_1
:
p_Q x_Q

-----Output-----
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between.

-----Sample Input-----
4 3
1 2
2 3
2 4
2 10
1 100
3 1

-----Sample Output-----
100 110 111 110

The tree in this input is as follows:

Each operation changes the values of the counters on the vertices as follows:
 - Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.
 - Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.
 - Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.

Difficulty: MEDIUM

Starter code:

Solutions:
import collections
(n, q) = map(int, input().split())
d = collections.defaultdict(list)
score = [0 for i in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	d[a].append(b)
for _ in range(q):
	(p, x) = map(int, input().split())
	score[p - 1] += x
for node in range(1, n + 1):
	child = d[node]
	for c in child:
		score[c - 1] += score[node - 1]
print(' '.join(map(str, score)))


(n, k) = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(n - 1)]
qs = [list(map(int, input().split())) for _ in range(k)]
ws = [0 for _ in range(n)]
for q in qs:
	ws[q[0] - 1] += q[1]
ds = [[] for _ in range(n)]
for l in ls:
	ds[l[0] - 1].append(l[1] - 1)
for i in range(0, n):
	for x in ds[i]:
		ws[x] += ws[i]
for i in range(n):
	print(ws[i])


def main():
	(n, q) = map(int, input().split())
	ab = [list(map(int, input().split())) for _ in range(n - 1)]
	tree = [list() for _ in range(n)]
	score = [0] * n
	for (a, b) in ab:
		(a, b) = (a - 1, b - 1)
		tree[a].append(b)
		tree[b].append(a)
	e = [0]
	while len(e) > 0:
		i = e.pop()
		for j in tree[i]:
			tree[j].remove(i)
			e.append(j)
	px = [list(map(int, input().split())) for _ in range(q)]
	for (p, x) in px:
		p -= 1
		score[p] += x
	add(tree, score)
	print(*score)

def add(tree, score):
	s = tree[0][:]
	for i in s:
		score[i] += score[0]
	while len(s) > 0:
		t = s.pop()
		for i in tree[t]:
			s.append(i)
			score[i] += score[t]

def __starting_point():
	main()
__starting_point()


I = lambda : map(int, input().split())
(n, q) = I()
r = [0] * n
e = [[] for _ in range(n)]
y = [0] + [1] * n
s = [0]
for _ in range(n - 1):
	(a, b) = I()
	e[a - 1] += (b - 1,)
	e[b - 1] += (a - 1,)
for _ in range(q):
	(p, x) = I()
	r[p - 1] += x
while s:
	u = s.pop()
	v = r[u]
	for c in e[u]:
		if y[c]:
			y[c] = 0
			r[c] += v
			s += (c,)
print(*r)


from sys import stdin
(N, Q) = list(map(int, stdin.readline().rstrip().split(' ')))
edge = [list(map(int, stdin.readline().rstrip().split(' '))) for _ in range(N - 1)]
vals = [list(map(int, stdin.readline().rstrip().split(' '))) for _ in range(Q)]
res = [0] * N
for (i, v) in vals:
	res[i - 1] = res[i - 1] + v
edge.sort()
for (p, d) in edge:
	res[d - 1] = res[d - 1] + res[p - 1]
print(' '.join(map(str, res)))


(N, Q) = map(int, input().split(' '))
points = [0 for _ in range(N + 1)]
g = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split(' '))
	g[a].append(b)
for _ in range(Q):
	(p, x) = map(int, input().split(' '))
	points[p] += x
q = [1]
while q:
	node = q.pop()
	for child in g[node]:
		points[child] += points[node]
		q.append(child)
print(*points[1:])


(n, q) = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	graph[a].append(b)
	graph[b].append(a)
weight = [0 for i in range(n)]
for i in range(q):
	(p, x) = map(int, input().split())
	weight[p - 1] += x
st = [0]
visit = [False for i in range(n)]
while not len(st) == 0:
	now = st.pop()
	visit[now] = True
	for e in graph[now]:
		if visit[e]:
			continue
		weight[e] += weight[now]
		st.append(e)
print(' '.join(map(str, weight)))


import collections, sys

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
(N, Q) = LI()
ab = [LI() for _ in range(N - 1)]
px = [LI() for _ in range(Q)]
ans = [0] * (N + 1)
graph = {i: collections.deque() for i in range(1, N + 1)}
for (a, b) in ab:
	graph[a].append(b)
	graph[b].append(a)
for (p, x) in px:
	ans[p] += x
seen = [0] * (N + 1)
stack = []

def dfs():
	seen[1] = 1
	stack.append(1)
	while stack:
		s = stack.pop()
		if not graph[s]:
			continue
		for j in range(len(graph[s])):
			g_NO = graph[s].popleft()
			if seen[g_NO]:
				continue
			seen[g_NO] = 1
			stack.append(g_NO)
			ans[g_NO] += ans[s]
dfs()
print(*ans[1:])


((n, q), *t) = [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) = map(int, input().split())
g = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
ans = [0] * N
for i in range(Q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
q = [0]
while q:
	p = q.pop()
	for c in g[p]:
		ans[c] += ans[p]
		q.append(c)
print(' '.join([str(x) for x in ans]))


import sys
input = sys.stdin.readline
from heapq import heappush, heappop
(n, q) = map(int, input().split())
a = []
for i in range(n - 1):
	heappush(a, list(map(int, input().split())))
p = [0] * q
x = [0] * q
c = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	c[p - 1] += x
ans = [0] * n
ans[0] = c[0]
for _ in range(n - 1):
	l = heappop(a)
	ans[l[1] - 1] = ans[l[0] - 1] + c[l[1] - 1]
print(*ans)


(N, Q) = map(int, input().split())
es = [[] for i in range(N)]
value = [0] * N
for i in range(N - 1):
	(a, b) = map(int, input().split())
	es[a - 1] += [b - 1]
	es[b - 1] += [a - 1]
for i in range(Q):
	(p, x) = map(int, input().split())
	value[p - 1] += x
stuck = [0]
log = [1] * N
log[0] = 0
while stuck:
	e = stuck.pop()
	for f in es[e]:
		if log[f]:
			log[f] = 0
			value[f] += value[e]
			stuck += [f]
print(*value)


def main():
	(N, Q) = map(int, input().split())
	ab = [list(map(int, input().split())) for _ in range(N - 1)]
	ab.sort()
	plus = [0 for _ in range(N)]
	for _ in range(Q):
		(p, x) = map(int, input().split())
		plus[p - 1] += x
	for (a, b) in ab:
		plus[b - 1] += plus[a - 1]
	for p in plus:
		print(p)
main()


(N, Q) = map(int, input().split())
edge = [[] for _ in range(N)]
cnt = [0] * N
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	edge[a - 1] += (b - 1,)
	edge[b - 1] += (a - 1,)
for _ in range(Q):
	(p, x) = map(int, input().split())
	cnt[p - 1] += x
done = [False] * N
done[0] = True
stack = [0]
while stack:
	par = stack.pop()
	for child in edge[par]:
		if not done[child]:
			done[child] = True
			cnt[child] += cnt[par]
			stack.append(child)
print(*cnt)


import sys
sys.setrecursionlimit(10 ** 6)
(N, Q) = map(int, input().split())
g = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
for _ in range(Q):
	(a, b) = map(int, input().split())
	a -= 1
	point[a] += b

def dfs(n, pre=-1):
	for ne in g[n]:
		if ne == pre:
			continue
		point[ne] += point[n]
		dfs(ne, n)
dfs(0)
print(*point)


(N, Q) = map(int, input().split())
EDGES = [list(map(int, input().split())) for i in range(N - 1)]
OPES = [list(map(int, input().split())) for i in range(Q)]
VALUES = [0 for i in range(N)]
for o in OPES:
	VALUES[o[0] - 1] += o[1]
EDGES.sort(key=lambda e: e[0])
for e in EDGES:
	VALUES[e[1] - 1] += VALUES[e[0] - 1]
print(' '.join(map(str, VALUES)))


def abc138d_ki():
	import heapq
	(n, q) = map(int, input().split())
	cnt = [0] * n
	graph = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		graph[a - 1].append(b - 1)
		graph[b - 1].append(a - 1)
	for _ in range(q):
		(p, x) = map(int, input().split())
		cnt[p - 1] += x
	qu = [(0, 0)]
	heapq.heapify(qu)
	check = [False] * n
	while len(qu) != 0:
		(h, no) = heapq.heappop(qu)
		check[no] = True
		for nxt in graph[no]:
			if not check[nxt]:
				cnt[nxt] += cnt[no]
				heapq.heappush(qu, (h + 1, nxt))
	for c in cnt:
		print(c, end=' ')
abc138d_ki()


(n, q) = map(int, input().split())
tree = [set() for i in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a].add(b)
	tree[b].add(a)
lazy = [0] * (n + 1)
cnt = 0
for _ in range(q):
	(x, v) = map(int, input().split())
	lazy[x] += v
que = [(1, 0)]
while que:
	(v, p) = que.pop()
	for x in tree[v]:
		if x == p:
			continue
		lazy[x] += lazy[v]
		que.append((x, v))
print(' '.join(map(str, lazy[1:])))


def main():
	(n, q) = map(int, input().split())
	a = [0] * (n - 1)
	c = [0 for i in range(n)]
	for i in range(n - 1):
		a[i] = list(map(int, input().split()))
	a.sort()
	for i in range(q):
		(x, y) = map(int, input().split())
		c[x - 1] += y
	for i in range(n - 1):
		c[a[i][1] - 1] += c[a[i][0] - 1]
	print(*c)
main()


def main():
	(_map, _range, _int) = (map, range, int)
	(n, q) = _map(_int, input().split())
	values = [0] * (n + 1)
	parents = [0] * (n + 1)
	for i in _range(n - 1):
		(a, b) = _map(_int, input().split())
		parents[b] = a
	for _ in _range(q):
		(p, x) = _map(_int, input().split())
		values[p] += x
	for i in _range(1, n + 1):
		values[i] += values[parents[i]]
	print(*values[1:])
main()


(N, Q) = map(int, input().split())
ans = [0] * N
ab = []
for i in range(1, N):
	ab.append(list(map(int, input().split())))
for j in range(Q):
	(pj, xj) = map(int, input().split())
	ans[pj - 1] += xj
ab.sort()
for i in range(N - 1):
	ans[ab[i][1] - 1] += ans[ab[i][0] - 1]
print(' '.join(map(str, ans)))


from collections import Counter
(n, q) = map(int, input().split())
d = {}
for i in range(n - 1):
	(_a, _b) = map(int, input().split())
	d[_b] = _a
ans = [0] * n
for i in range(q):
	(_p, _x) = map(int, input().split())
	ans[_p - 1] += _x
for i in range(1, n):
	ans[i] += ans[d.get(i + 1) - 1]
print(' '.join(map(str, ans)))


import sys
import math
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inm = lambda : map(int, sys.stdin.readline().split())
inl = lambda : list(inm())
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

class Node:

	def __init__(self):
		self.edge = []
		self.count = 0

def dfs(tree, node, p_node, p_count, counts):
	count = tree[node].count + p_count
	counts[node] = count
	for x in tree[node].edge:
		if x == p_node:
			continue
		dfs(tree, x, node, count, counts)
(N, Q) = inm()
tree = []
for _ in range(N):
	tree.append(Node())
for _ in range(N - 1):
	(a, b) = inm()
	tree[a - 1].edge.append(b - 1)
	tree[b - 1].edge.append(a - 1)
for _ in range(Q):
	(p, x) = inm()
	tree[p - 1].count += x
val = []
for _ in range(N):
	val.append(0)
dfs(tree, 0, -1, 0, val)
counts_str = [str(n) for n in val]
s = ' '.join(counts_str)
print(s)


(n, m) = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	edges[a].append(b)
	edges[b].append(a)
list = [0] * n
for _ in range(m):
	(p, q) = map(int, input().split())
	list[p - 1] += q
stack = [0]
lity = [0] * n
while stack:
	x = stack.pop()
	lity[x] = 1
	for y in edges[x]:
		if lity[y] == 1:
			continue
		list[y] += list[x]
		stack.append(y)
print(*list)


import sys
sys.setrecursionlimit(10 ** 7)
(n, q) = map(int, input().split())
ans = [0 for _ in range(n)]
gra = [[] for _ in range(n)]
visited = [0 for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	gra[a - 1].append(b - 1)
	gra[b - 1].append(a - 1)
for _ in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x

def dfs(st):
	temp = gra[st]
	for i in temp:
		if visited[i] == 0:
			visited[i] += 1
			ans[i] += ans[st]
			dfs(i)
visited[0] += 1
dfs(0)
for h in range(n):
	ans[h] = str(ans[h])
print(' '.join(ans))


(N, Q) = map(int, input().split())
T = [0] * (N + 1)
V = [0] * (N + 1)
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	T[b] = a
for _ in range(Q):
	(p, x) = map(int, input().split())
	V[p] += x
for i in range(1, N + 1):
	V[i] += V[T[i]]
print(*V[1:])


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
ans = [0 for _ in range(n)]
for _ in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
tree = [[] for _ in range(n)]
for (a, b) in ab:
	tree[a - 1].append(b - 1)
del ab
for (index, i) in enumerate(tree):
	for j in i:
		ans[j] += ans[index]
print(' '.join(map(str, ans)))


from collections import deque
(n, q) = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
s = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	s[p - 1] += x
que = deque([0])
f = [0] * n
f[0] = 1
while que:
	v = que.popleft()
	c = s[v]
	for w in g[v]:
		if f[w]:
			continue
		f[w] = 1
		s[w] += c
		que.append(w)
print(*s)


import sys
sys.setrecursionlimit(10 ** 6)

def dfs(v, pv):
	for nv in g[v]:
		if nv == pv:
			continue
		cnt[nv] += cnt[v]
		dfs(nv, v)
((N, Q), *ABPX) = [list(map(int, s.split())) for s in open(0)]
g = [set() for _ in range(N)]
for (a, b) in ABPX[:N - 1]:
	g[a - 1].add(b - 1)
	g[b - 1].add(a - 1)
cnt = [0] * N
for (p, x) in ABPX[N - 1:]:
	cnt[p - 1] += x
dfs(0, -1)
print(*cnt)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
(n, q) = map(int, input().split())
c = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	c[a].append(b)
	c[b].append(a)
px = [0] * n
for I in range(q):
	(p, x) = map(int, input().split())
	px[p - 1] += x
ans = [0] * n

def dfs(g, h=-1):
	ans[g] = ans[h] + px[g]
	for i in c[g]:
		if i == h:
			continue
		dfs(i, g)
dfs(0)
print(*ans)


import collections
(n, q) = map(int, input().split())
value = ['-'] * (n + 1)
connected = [set() for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	connected[a].add(b)
	connected[b].add(a)
for i in range(q):
	(p, x) = map(int, input().split())
	if value[p] == '-':
		value[p] = 0
	value[p] -= x
queue = collections.deque(connected[1])
if value[1] == '-':
	value[1] = 0
else:
	value[1] = -value[1]
for i in queue:
	if value[i] == '-':
		value[i] = 0
	else:
		value[i] = -value[i]
	value[i] += value[1]
while queue:
	s = queue.popleft()
	v = value[s]
	for i in connected[s]:
		vi = value[i]
		if vi == '-' or vi < 0:
			if vi == '-':
				vi = 0
			value[i] = -(vi - v)
			queue.append(i)
print(' '.join((str(i) for i in value[1:])))


(N, Q) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PQ = [list(map(int, input().split())) for _ in range(Q)]
l = [[] for _ in range(N)]
ans = [0] * N
for (a, b) in AB:
	l[a - 1].append(b - 1)
for (p, q) in PQ:
	ans[p - 1] += q
for i in range(N - 1):
	for j in l[i]:
		ans[j] += ans[i]
print(*ans)


(N, Q) = map(int, input().split())
adj = [list() for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	adj[a - 1].append(b - 1)
memo = [0] * N
for _ in range(Q):
	(p, x) = map(int, input().split())
	memo[p - 1] += x
result = [None] * N
stack = [(0, 0)]
while stack:
	(v, a) = stack.pop()
	a += memo[v]
	result[v] = a
	for u in adj[v]:
		stack.append((u, a))
print(*result)


(n, q) = map(int, input().split())
r = [[] for i in range(n)]
v = [0 for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	r[a - 1].append(b - 1)
for i in range(q):
	(p, x) = map(int, input().split())
	v[p - 1] += x
for i in range(n):
	for y in r[i]:
		v[y] += v[i]
print(' '.join(map(str, v)))


(n, q) = map(int, input().split())
to = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	to[a - 1].append(b - 1)
cost = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	p -= 1
	cost[p] += x
from collections import deque
que = deque([0])
while que:
	f = que.popleft()
	for t in to[f]:
		que.append(t)
		cost[t] += cost[f]
print(' '.join([str(x) for x in cost]))


(n, q) = map(int, input().split())
ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	e[a].append(b)
qs = [0] * (n + 1)
for _ in range(q):
	(p, q) = map(int, input().split())
	qs[p] += q
target = [1]
while len(target):
	t = target.pop()
	ct[t] += qs[t]
	for nt in e[t]:
		target.append(nt)
		ct[nt] += ct[t]
print(*ct[1:])


(N, Q) = map(int, input().split())
tree = [[] for i in range(N + 1)]
counter = [0] * (N + 1)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	tree[b].append(a)
for i in range(Q):
	(p, x) = map(int, input().split())
	counter[p] += x
for i in range(1, N + 1):
	for pn in tree[i]:
		counter[i] += counter[pn]
print(' '.join(map(str, counter[1:])))


(N, Q) = map(int, input().split())
E = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	E[a - 1].append(b - 1)
xs = [0] * N
for i in range(Q):
	(p, x) = map(int, input().split())
	xs[p - 1] += x
rs = [0] * N
q = [0]
while q:
	p = q.pop()
	rs[p] += xs[p]
	for c in E[p]:
		rs[c] += rs[p]
		q.append(c)
print(' '.join(map(str, rs)))


(N, Q) = map(int, input().split())
Ki_Oya = dict()
for i in range(N - 1):
	(A, B) = map(int, input().split())
	Ki_Oya[B - 1] = A - 1
Counter_list = [0] * N
for i in range(Q):
	(P, X) = map(int, input().split())
	Counter_list[P - 1] += X
print(Counter_list[0], end=' ')
for i in range(1, len(Counter_list)):
	Counter_list[i] += Counter_list[Ki_Oya[i]]
	print(Counter_list[i], end=' ')
print('')


from collections import defaultdict
(N, Q) = map(int, input().split())
E = defaultdict(list)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	E[a - 1].append(b - 1)
ans = [0] * N
for i in range(Q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
for i in range(N):
	for t in E[i]:
		ans[t] += ans[i]
print(*ans)


(n, q) = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	ki[b] = a
c = [0] * (n + 1)
for i in range(q):
	(p, x) = map(int, input().split())
	c[p] += x
for i in range(1, n + 1):
	c[i] += c[ki[i]]
print(' '.join(map(str, c[1:])))


(n, q) = map(int, input().split())
children_map = [None] * n
vals = [0] * n
for i in range(1, n):
	(a, b) = map(int, input().split())
	children_map[b - 1] = a - 1
for j in range(q):
	(p, x) = map(int, input().split())
	vals[p - 1] += x
for i in range(n):
	parent = children_map[i]
	if parent is not None:
		vals[i] += vals[parent]
print(*vals)


import sys
sys.setrecursionlimit(10 ** 6)

def dfs(tree, n, ans):
	for i in tree[n]:
		ans[i] += ans[n]
		tree[i].remove(n)
		dfs(tree, i, ans)
(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
g = [[] for _ in range(n)]
for i in range(n - 1):
	g[ab[i][0] - 1].append(ab[i][1] - 1)
	g[ab[i][1] - 1].append(ab[i][0] - 1)
ans = [0] * n
for i in range(q):
	ans[px[i - 1][0] - 1] += px[i - 1][1]
dfs(g, 0, ans)
print(*ans)


(N, Q) = map(int, input().split(' '))
ns = [list(map(int, input().split(' '))) for _ in range(N - 1)]
vs = [list(map(int, input().split(' '))) for _ in range(Q)]
dic = [[] for _ in range(N)]
rlt = [0] * N
for i in range(N - 1):
	dic[ns[i][0] - 1] += [ns[i][1] - 1]
for j in range(Q):
	rlt[vs[j][0] - 1] += vs[j][1]
for k in range(N):
	for l in dic[k]:
		rlt[l] += rlt[k]
print(' '.join(map(str, rlt)))


import sys
sys.setrecursionlimit(10 ** 7)
(N, Q) = [int(n) for n in input().split()]
tree_list = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b) = [int(n) - 1 for n in input().split()]
	tree_list[a].append(b)
	tree_list[b].append(a)
score_list = [0] * N
for j in range(Q):
	(p, x) = [int(n) for n in input().split()]
	score_list[p - 1] += x
reached = [False] * N

def dfs(v):
	reached[v] = True
	for next_v in tree_list[v]:
		if reached[next_v] == True:
			continue
		score_list[next_v] += score_list[v]
		dfs(next_v)
dfs(0)
print(*score_list)


import sys
sys.setrecursionlimit(10 ** 9)
(n, q) = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
subtree_size = [0] * n
cnt = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	p -= 1
	cnt[p] += x
ans = [0] * n

def dfs(G, v, p):
	ans[v] += cnt[v]
	for nv in G[v]:
		if nv == p:
			continue
		cnt[nv] += cnt[v]
		dfs(G, nv, v)
	subtree_size[v] = 1
	for c in G[v]:
		if c == p:
			continue
		subtree_size[v] += subtree_size[c]
root = 0
dfs(G, root, -1)
for i in range(n):
	print(ans[i], end=' ')


(N, Q) = map(int, input().split())
edge = []
for _ in range(N - 1):
	edge.append(list(map(int, input().split())))
edge = sorted(edge)
n2w = [0] * (N + 1)
for _ in range(Q):
	tmp = list(map(int, input().split()))
	n2w[tmp[0]] += tmp[1]
for (a, b) in edge:
	n2w[b] += n2w[a]
print(*n2w[1:])


(N, Q) = map(int, input().split(' '))
out_put_list = [0] * N
tree_list = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split(' '))
	tree_list[a - 1].append(b - 1)
for _ in range(Q):
	(p, x) = map(int, input().split(' '))
	out_put_list[p - 1] += x
for i in range(len(tree_list)):
	for num in tree_list[i]:
		out_put_list[num] += out_put_list[i]
print(*out_put_list)


(n, q) = map(int, input().split())
arr = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	arr[a - 1].append(b)
ans = [0 for _ in range(n)]
for _ in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
for (i, c) in enumerate(ans):
	for j in arr[i]:
		ans[j - 1] += c
print(*ans)


import sys
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)

def main():

	def dfs(v, s):
		if notseen[v]:
			scores[v] += s
			notseen[v] = 0
			for nextv in gg[v]:
				dfs(nextv, scores[v])
	data = tuple(map(int, read().split()))
	(n, q) = (data[0], data[1])
	gg = {i: set() for i in range(1, n + 1)}
	for (i1, v1) in zip(data[2:n * 2:2], data[3:n * 2:2]):
		gg[v1].add(i1)
		gg[i1].add(v1)
	scores = [0] * (n + 1)
	for (j1, v1) in zip(data[n * 2::2], data[n * 2 + 1::2]):
		scores[j1] += v1
	notseen = [1] * (n + 1)
	dfs(1, 0)
	print(*scores[1:], sep=' ')

def __starting_point():
	main()
__starting_point()


(a, b) = map(int, input().split())
y = []
for i in range(a - 1):
	v = list(map(int, input().split()))
	y.append(v)
y.sort(key=lambda n: n[0])
ans = [0] * a
for j in range(b):
	(c, d) = map(int, input().split())
	ans[c - 1] = ans[c - 1] + d
for k in range(a - 1):
	ans[y[k][1] - 1] = ans[y[k][1] - 1] + ans[y[k][0] - 1]
print(*ans, sep=' ')


import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
(n, q) = map(int, input().split())
l = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	l[a - 1].append(b - 1)
	l[b - 1].append(a - 1)
px = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	px[p - 1] += x
ans = [0] * n

def dsf(index, u):
	ans[index] = ans[u] + px[index]
	for i in l[index]:
		if i == u:
			continue
		dsf(i, index)
dsf(0, -1)
print(*ans)


(n, q) = map(int, input().split())
tree = [[] for i in range(n)]
v = [0] * n
for i in range(n - 1):
	(a1, b1) = [int(i) for i in input().split()]
	tree[a1 - 1].append(b1)
for i in range(q):
	(p1, x1) = [int(i) for i in input().split()]
	v[p1 - 1] += x1
for i in range(n):
	for j in range(len(tree[i])):
		v[tree[i][j] - 1] += v[i]
for i in range(n):
	print(str(v[i]) + ' ', end='')


(N, Q) = map(int, input().split(' '))
A = [0] * N
B = [0 for j in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split(' '))
	A[b - 1] = a - 1
for j in range(Q):
	tmp = list(map(int, input().split(' ')))
	B[tmp[0] - 1] += tmp[1]
for i in range(1, N):
	B[i] += B[A[i]]
for i in range(N):
	print(B[i], end=' ')


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n - 1)]
px = [list(map(int, input().split())) for i in range(q)]
parent = [0 for i in range(n)]
for i in range(n - 1):
	parent[ab[i][1] - 1] = ab[i][0]
ans = [0 for i in range(n)]
for i in range(q):
	ans[px[i][0] - 1] += px[i][1]
for i in range(1, n):
	if parent[i] != 0:
		ans[i] += ans[parent[i] - 1]
print(' '.join(map(str, ans)))


import sys
sys.setrecursionlimit(1 << 30)

def dfs(x):
	for y in edges[x]:
		if y != parent[x]:
			parent[y] = x
			count[y] += count[x]
			dfs(y)
(N, Q) = map(int, input().split())
edges = [[] for _ in range(N + 1)]
count = [0] * (N + 1)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	edges[a].append(b)
	edges[b].append(a)
for i in range(Q):
	(p, x) = map(int, input().split())
	count[p] += x
parent = [-1] * (N + 1)
dfs(1)
print(*count[1:])


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n - 1)]
ab.sort()
p = [0] * n
for i in range(q):
	(a, b) = map(int, input().split())
	p[a - 1] += b
s = ''
for i in ab:
	p[i[1] - 1] += p[i[0] - 1]
print(*p)


(N, Q) = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(N - 1)]
p = [list(map(int, input().split())) for _ in range(Q)]
parent = [0] * (N + 1)
count = [0] * (N + 1)
for t in s:
	parent[t[1]] = t[0]
for u in p:
	count[u[0]] += u[1]
dp = [0] * (N + 1)
for i in range(1, N + 1):
	dp[i] = dp[parent[i]] + count[i]
for i in dp[1:]:
	print(i, end=' ')


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
(N, Q) = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N - 1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for (a, b) in AB:
	graph[a].append(b)
	graph[b].append(a)
value = [0] * (N + 1)
for (p, x) in PX:
	value[p] += x

def dfs(v, parent, add):
	value[v] += add
	for x in graph[v]:
		if x == parent:
			continue
		dfs(x, v, value[v])
dfs(1, 0, 0)
answer = ' '.join(map(str, value[1:]))
print(answer)


(N, Q) = map(int, input().split())
dic = {}
lst = [0] * (N + 1)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	if not a in dic.keys():
		dic[a] = []
	dic[a].append(b)
for i in range(Q):
	(p, x) = map(int, input().split())
	lst[p] += x
for i in range(1, N + 1):
	print(lst[i], end=' ')
	if i in dic.keys():
		tmp_lst = dic[i]
		for j in tmp_lst:
			lst[j] += lst[i]
print()


import sys
sys.setrecursionlimit(10 ** 9)
(N, Q) = map(int, input().split())
L = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	L[a - 1].append(b - 1)
	L[b - 1].append(a - 1)
S = [0] * N
for _ in range(Q):
	(p, x) = map(int, input().split())
	S[p - 1] += x

def search(p, q=-1):
	for a in L[p]:
		if a != q:
			S[a] += S[p]
			search(a, p)
search(0)
print(*S)


import sys
sys.setrecursionlimit(1 << 30)
(N, Q) = map(int, input().split())

def dfs(x, score):
	for y in Tree[x]:
		if Parent[x] != y:
			Parent[y] = x
			score[y] += score[x]
			dfs(y, score)
Tree = [[] for i in range(N + 1)]
Parent = [0] * (N + 1)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	Tree[a].append(b)
	Tree[b].append(a)
score = [0] * (N + 1)
for j in range(Q):
	(p, x) = map(int, input().split())
	score[p] += x
dfs(1, score)
print(*score[1:], end='\t')


import collections
(n, q) = map(int, input().split())
cnt = [0] * (n + 1)
g = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
for i in range(q):
	(v, val) = map(int, input().split())
	cnt[v] += val
q = collections.deque()
q.append(1)
checked = [0] * (n + 1)
while q:
	v = q.pop()
	checked[v] = 1
	for i in g[v]:
		if checked[i] == 1:
			continue
		cnt[i] += cnt[v]
		q.append(i)
print(*cnt[1:])


(n, q) = map(int, input().split())
rl = [0] * n
scores = [0] * n
for i in range(n - 1):
	(a, b) = map(int, input().split())
	rl[b - 1] = a - 1
for j in range(q):
	(p, x) = map(int, input().split())
	scores[p - 1] += x
for k in range(1, n):
	scores[k] += scores[rl[k]]
print(*scores)


(n, q) = map(int, input().split())
lis = [0 for i in range(n)]
li = [0 for i in range(n)]
tree = [0 for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[b - 1] = a - 1
for i in range(q):
	(c, d) = map(int, input().split())
	li[c - 1] += d
lis[0] = li[0]
for i in range(1, n):
	lis[i] = lis[tree[i]] + li[i]
for i in range(n):
	lis[i] = str(lis[i])
print(' '.join(lis))


from sys import stdin
(n, q) = map(int, input().split())
cnt = [0] * n
root = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, stdin.readline().split())
	root[a - 1].append(b - 1)
for i in range(q):
	(p, x) = map(int, stdin.readline().split())
	cnt[p - 1] += x
tmparr = [0]
while tmparr:
	tmpi = tmparr.pop()
	for i in root[tmpi]:
		cnt[i] += cnt[tmpi]
	tmparr += root[tmpi]
print(*cnt)


(N, Q) = map(int, input().split())
pNode = [1] * N
c = [0] * N
for i in range(N - 1):
	(a, b) = map(int, input().split())
	pNode[b - 1] = a - 1
for i in range(Q):
	(p, x) = map(int, input().split())
	c[p - 1] += x
for i in range(1, N):
	c[i] += c[pNode[i]]
print(*c)


(N, Q) = map(int, input().split())
dictionary = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	dictionary[a].append(b)
num = [0] * (N + 1)
for i in range(Q):
	(p, x) = map(int, input().split())
	num[p] += x
for i in range(1, N + 1):
	print(num[i])
	for j in range(0, len(dictionary[i])):
		num[dictionary[i][j]] += num[i]


from collections import deque
(n, q) = map(int, input().split())
tree = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	tree[a].append(b)
	tree[b].append(a)
count = [0] * n
for _ in range(q):
	(p, cnt) = map(int, input().split())
	count[p - 1] += cnt
stack = deque([[0, 0, -1]])
while stack:
	(num, cnt, pr) = stack.pop()
	count[num] += cnt
	for k in tree[num]:
		if k == pr:
			continue
		stack.append([k, count[num], num])
print(*count)


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
tree = {}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a in tree:
		tree[a].append(b)
	else:
		tree[a] = [b]
op = [0] * (n + 1)
for i in range(q):
	(p, x) = map(int, input().split())
	op[p] += x
for (root, reaf) in tree.items():
	for i in reaf:
		op[i] += op[root]
print(*op[1:])


(n, q) = map(int, input().split())
rl = [0] * n
al = [0] * n
for i in range(n - 1):
	(a, b) = map(int, input().split())
	rl[b - 1] = a - 1
for j in range(q):
	(p, x) = map(int, input().split())
	al[p - 1] += x
for k in range(n):
	if k == 0:
		pass
	else:
		al[k] += al[rl[k]]
print(*al)


(n, q) = map(int, input().split())
edge = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a].append(b)
	edge[b].append(a)
px = [0 for i in range(n + 1)]
for i in range(q):
	(p, x) = map(int, input().split())
	px[p] += x
s = [1]
c = [1] * (n + 1)
c[1] = 0
while s:
	t = s.pop()
	for i in edge[t]:
		if c[i]:
			c[i] = 0
			px[i] += px[t]
			s.append(i)
print(' '.join(map(str, px[1:])))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
(n, q) = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
P = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	P[p - 1] += x

def dfs(v, pv):
	for nv in G[v]:
		if nv != pv:
			P[nv] += P[v]
			dfs(nv, v)
dfs(0, 0)
print(*P)


from collections import deque
import numpy as np
(N, Q) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N - 1)]
P = [list(map(int, input().split())) for _ in range(Q)]
link = [[] for _ in range(N)]
for i in range(N - 1):
	link[A[i][0] - 1].append(A[i][1] - 1)
	link[A[i][1] - 1].append(A[i][0] - 1)
ans = [0 for _ in range(N)]
for i in range(Q):
	ans[P[i][0] - 1] += P[i][1]
dist = [-1 for _ in range(N)]
dist[0] = 0
d = deque([0])
while d:
	now = d.pop()
	for i in range(len(link[now])):
		if dist[link[now][i]] == -1:
			ans[link[now][i]] += ans[now]
			dist[link[now][i]] = 0
			d.append(link[now][i])
for i in range(N):
	if i != N - 1:
		print(ans[i], end=' ')
	else:
		print(ans[i])


import sys
sys.setrecursionlimit(10 ** 6)

def input():
	return sys.stdin.readline()[:-1]
(N, Q) = map(int, input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
for _ in range(Q):
	(a, b) = map(int, input().split())
	a = a - 1
	point[a] += b

def dfs(now, prev=-1):
	for next in graph[now]:
		if next == prev:
			continue
		point[next] += point[now]
		dfs(next, now)
dfs(0)
print(*point)


from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)
(n, q) = map(int, input().split())
node = [[] for _ in range(n + 1)]
counter = [0 for _ in range(n + 1)]
visited = [0 for _ in range(n + 1)]
point_dic = defaultdict(int)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	node[a].append(b)
	node[b].append(a)
for _ in range(q):
	(p, x) = map(int, input().split())
	point_dic[p] += x

def dfs(now, before_point):
	if visited[now]:
		return
	if point_dic[now]:
		point = point_dic[now] + before_point
	else:
		point = before_point
	visited[now] = 1
	counter[now] += point
	for i in node[now]:
		if visited[i]:
			continue
		dfs(i, point)
dfs(1, 0)
print(' '.join(map(str, counter[1:])))


(n, q) = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
ans = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
f = [1] * n
st = [0]
while st:
	v = st.pop()
	f[v] = 0
	for u in g[v]:
		if f[u]:
			ans[u] += ans[v]
			st.append(u)
print(*ans)


(n, q) = map(int, input().split())
ab = []
for i in range(n - 1):
	(x, y) = map(int, input().split())
	ab.append([x, y])
ab.sort()
ans = [0] * n
cnt = [0] * n
for i in range(q):
	(x, y) = map(int, input().split())
	ans[x - 1] += y
for i in range(n - 1):
	ans[ab[i][1] - 1] += ans[ab[i][0] - 1]
print(*ans)


(N, Q) = (int(i) for i in input().split())
ab = [[int(i) for i in input().split()] for i in range(N - 1)]
px = [[int(i) for i in input().split()] for i in range(Q)]
ab.sort()
weight = [0] * N
for i in range(len(px)):
	weight[px[i][0] - 1] += px[i][1]
for g in range(len(ab)):
	weight[ab[g][1] - 1] += weight[ab[g][0] - 1]
print(*weight)


(N, Q) = map(int, input().split())
l = [None] * N
l[0] = [1, 1, 0]
for i in range(1, N):
	(a, b) = map(int, input().split())
	l[i] = [b, a, 0]
l.sort()
for i in range(Q):
	(p, x) = map(int, input().split())
	l[p - 1][2] += x
t = [l[0][2]] + [None] * (N - 1)
for i in range(1, N):
	t[i] = t[l[i][1] - 1] + l[i][2]
print(*t)


(n, q) = map(int, input().split())
point_array = [list(map(int, input().split())) for i in range(n - 1)]
action_array = [list(map(int, input().split())) for i in range(q)]
point_array.sort()
solution = [0] * n
for i in range(q):
	solution[action_array[i][0] - 1] += action_array[i][1]
for i in range(n - 1):
	solution[point_array[i][1] - 1] += solution[point_array[i][0] - 1]
print(*solution)


(n, q) = map(int, input().split())
T = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	T[a - 1].append(b - 1)
	T[b - 1].append(a - 1)
C = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	C[p - 1] += x
S = [0]
P = [0] * n
while S:
	s = S.pop()
	for t in T[s]:
		if t == P[s]:
			continue
		P[t] = s
		S.append(t)
		C[t] += C[s]
print(' '.join(map(str, C)))


from collections import deque

def nearlist(N, LIST):
	NEAR = [set() for _ in range(N)]
	for (a, b) in LIST:
		NEAR[a - 1].add(b - 1)
		NEAR[b - 1].add(a - 1)
	return NEAR

def bfs(NEAR):
	(que, frag) = (deque([0]), set([0]))
	while que:
		q = que.popleft()
		for i in NEAR[q]:
			if i in frag:
				continue
			ans[i] += ans[q]
			(que.append(i), frag.add(i))
	return
(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
ans = [0] * n
for (p, x) in px:
	ans[p - 1] += x
near = nearlist(n, ab)
bfs(near)
print(*ans)


(n, q) = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
cnt = [0] * (n + 1)
for i in range(q):
	(p, x) = map(int, input().split())
	cnt[p] += x
flag = [1] * (n + 1)
stack = [1]
while stack:
	v = stack.pop()
	flag[v] = 0
	for k in graph[v]:
		if flag[k]:
			cnt[k] += cnt[v]
			stack.append(k)
print(*cnt[1:])


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
(n, q) = map(int, input().split())
t = [[] for _ in range(n)]
c = [0 for _ in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	t[a - 1].append(b - 1)
	t[b - 1].append(a - 1)
for i in range(q):
	(p, x) = map(int, input().split())
	c[p - 1] += x

def dsf(ci, pi):
	for i in t[ci]:
		if i != pi:
			c[i] += c[ci]
			dsf(i, ci)
dsf(0, -1)
print(*c)


(n, q) = map(int, input().split())
d = {}
ans = [0] * (n + 1)
for i in range(n - 1):
	(sta, gol) = map(int, input().split())
	d[gol] = sta
for i in range(q):
	(sta, val) = map(int, input().split())
	ans[sta] += val
for i in range(n):
	gol = i + 1
	if gol in d:
		ans[gol] += ans[d[gol]]
for i in range(n):
	print(ans[i + 1], ' ', end='')


(N, Q) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N - 1)]
px = [list(map(int, input().split())) for i in range(Q)]
cnt = [0] * N
for (p, x) in px:
	cnt[p - 1] += x
for (a, b) in sorted(ab):
	cnt[b - 1] += cnt[a - 1]
print(*cnt)


import sys
sys.setrecursionlimit(10 ** 9)

def f(p, q=-1):
	for i in c[p]:
		if i != q:
			A[i] += A[p]
			f(i, p)
(n, q) = map(int, input().split())
c = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	c[a - 1].append(b - 1)
	c[b - 1].append(a - 1)
A = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	A[p - 1] += x
f(0)
print(*A)


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
ab.sort(key=lambda x: x[0])
ans = [0] * n
for i in px:
	ans[i[0] - 1] += i[1]
for i in ab:
	ans[i[1] - 1] += ans[i[0] - 1]
print(*ans)


import sys
stdin = sys.stdin
na = lambda : map(int, stdin.readline().split())

def main():
	(N, Q) = na()
	ab = []
	for _ in range(N - 1):
		(a, b) = na()
		ab.append([a, b])
	ab.sort()
	counter = [0] * (N + 1)
	for _ in range(Q):
		(p, x) = na()
		counter[p] += x
	for i in range(N - 1):
		counter[ab[i][1]] += counter[ab[i][0]]
	print(*counter[1:])
main()


import sys
sys.setrecursionlimit(10 ** 7)
(n, q) = map(int, input().split())
edge = [[] for i in range(n)]
a = [0] * n
b = [0] * n
for i in range(n - 1):
	(x, y) = map(int, input().split())
	edge[x - 1].append(y - 1)
	edge[y - 1].append(x - 1)
for i in range(q):
	(p, x) = map(int, input().split())
	a[p - 1] += x

def dfs(node, tmp):
	a[node] += tmp
	b[node] = 1
	for i in edge[node]:
		if b[i] == 0:
			dfs(i, a[node])
dfs(0, 0)
print(*a)


(n, q) = map(int, input().split())
l = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	l[a].append(b)
c = [0 for i in range(n + 1)]
for i in range(q):
	(a, b) = map(int, input().split())
	c[a] += b
for i in range(n + 1):
	if l[i] != []:
		for x in l[i]:
			c[x] += c[i]
for i in range(1, len(c)):
	print(c[i], end=' ')


(N, Q) = map(int, input().split())
score = [0 for i in range(0, N + 1)]
edge = []
aba = edge.append
ope = []
pxa = ope.append
for _ in range(N - 1):
	aba(tuple(map(int, input().split())))
edge.sort()
for _ in range(Q):
	ope = tuple(map(int, input().split()))
	score[ope[0]] += ope[1]
for i in range(N - 1):
	score[edge[i][1]] += score[edge[i][0]]
score.remove(score[0])
print(*score)


(n, q) = map(int, input().split())
d = {i: [] for i in range(n)}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	d[a - 1].append(b - 1)
counter = [0 for i in range(n)]
for i in range(q):
	(p, x) = map(int, input().split())
	counter[p - 1] += x
for i in range(n - 1):
	for child in d[i]:
		counter[child] += counter[i]
print(' '.join(map(str, map(int, counter))))


def main():
	(N, Q) = [int(n) for n in input().split(' ')]
	edges = [[] for i in range(N)]
	counter = [0] * N
	for i in range(N - 1):
		(a, b) = [int(x) for x in input().split(' ')]
		edges[a - 1].append(b - 1)
		edges[b - 1].append(a - 1)
	for j in range(Q):
		(p, x) = [int(q) for q in input().split(' ')]
		counter[p - 1] += x
	to_visit = [0]
	checked = [1] + [0] * (N - 1)
	tree = [0] * N
	while len(to_visit) > 0:
		visiting = to_visit.pop()
		tree[visiting] += counter[visiting]
		for e in edges[visiting]:
			if checked[e] == 0:
				checked[e] = 1
				to_visit.append(e)
				tree[e] = tree[visiting]
	print(' '.join([str(s) for s in tree]))
main()


(n, q) = map(int, input().split())
v = [[0, 0] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	v[a].append(b)
	v[b].append(a)
for i in range(q):
	(p, x) = map(int, input().split())
	v[p][1] += x
q = [1]
while q:
	now = q.pop()
	v[now][0] = 1
	for i in v[now][2:]:
		if v[i][0] == 0:
			v[i][1] += v[now][1]
			q.append(i)
s = []
for i in v:
	s.append(i[1])
print(*s[1:])


(n, q) = map(int, input().split())
ko = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	ko[a - 1].append(b - 1)
ans = [0] * n
for i in range(q):
	(a, b) = map(int, input().split())
	ans[a - 1] += b
nex = [0]
while nex:
	p = nex.pop()
	for i in ko[p]:
		ans[i] += ans[p]
	nex += ko[p]
print(*ans)


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n - 1)]
ab.sort()
px = [list(map(int, input().split())) for i in range(q)]
p = [0 for i in range(n)]
for i in px:
	p[i[0] - 1] += i[1]
s = ''
for i in ab:
	p[i[1] - 1] += p[i[0] - 1]
print(' '.join(map(str, p)))


import sys
sys.setrecursionlimit(10 ** 7)
(N, Q) = map(int, input().split())
AB = [[] for i in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	AB[a].append(b)
X = [0] * (N + 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	X[p] += x

def recursive(p):
	for c in AB[p]:
		X[c] += X[p]
		recursive(c)
recursive(1)
print(' '.join(map(str, X[1:])))


from collections import defaultdict
(N, Q) = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(N - 1)]
p = [tuple(map(int, input().split())) for i in range(Q)]
d = defaultdict(list)
for (vert, childs) in l:
	d[vert].append(childs)
d_2 = defaultdict(int)
for i in range(1, N + 1):
	d_2[i] = 0
for (p, x) in p:
	d_2[p] += x
for n in d_2.keys():
	for m in d[n]:
		d_2[m] += d_2[n]
ans = d_2.values()
print(*ans)


(N, Q) = map(int, input().split())
parentNodes = [0] * (N + 1)
counter = [0] * (N + 1)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	parentNodes[b] = a
for _ in range(Q):
	(p, x) = map(int, input().split())
	counter[p] += x
for i in range(1, N + 1):
	counter[i] += counter[parentNodes[i]]
print(*counter[1:])


from collections import defaultdict
(N, Q) = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(N - 1)]
p_l = [tuple(map(int, input().split())) for i in range(Q)]
d = defaultdict(list)
for (f, g) in l:
	d[f].append(g)
d_2 = defaultdict(int)
for h in range(1, N + 1):
	d_2[h] = 0
for (p, x) in p_l:
	d_2[p] += x
for n in range(1, N + 1):
	for m in d[n]:
		d_2[m] += d_2[n]
print(*d_2.values())


import sys
sys.setrecursionlimit(10 ** 9)
f = lambda : map(int, sys.stdin.readline().split())
(n, q) = f()
g = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
c = [0] * n
for i in range(q):
	(v, x) = f()
	c[v - 1] += x

def dfs(v, p=-1):
	for i in g[v]:
		if i == p:
			continue
		c[i] += c[v]
		dfs(i, v)
dfs(0)
print(*c)


(n, q) = map(int, input().split())
k = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	k[a - 1].append(b - 1)
	k[b - 1].append(a - 1)
s = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	s[p - 1] += x
from collections import deque
d = deque()
d.append(0)
v = [False] * n
v[0] = True
while d:
	g = d.popleft()
	for i in k[g]:
		if v[i]:
			continue
		d.append(i)
		v[i] = True
		s[i] += s[g]
print(*s)


(n, q) = map(int, input().split())
d = {1: [0, 0]}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	d[b] = [a, 0]
for i in range(q):
	(p, x) = map(int, input().split())
	d[p][1] += x
for i in range(2, n + 1):
	d[i][1] += d[d[i][0]][1]
l = []
for i in sorted(d.keys()):
	l.append(d[i][1])
print(' '.join(map(str, l)))


(N, Q) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N - 1)]
A.sort()
cost = [0] * (N + 1)
for _ in range(Q):
	(a, b) = map(int, input().split())
	cost[a] += b
for a in A:
	cost[a[1]] += cost[a[0]]
print(*cost[1:])


import sys
sys.setrecursionlimit(10 ** 9)
(N, Q) = map(int, input().split())
AB_TREE = [[] for i in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	AB_TREE[b].append(a)
	AB_TREE[a].append(b)
ans = [0] * (N + 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	p -= 1
	ans[p] += x

def dfs(v, p):
	for to in AB_TREE[v]:
		if to == p:
			continue
		ans[to] += ans[v]
		dfs(to, v)
dfs(0, -1)
for i in range(N):
	print(ans[i], end=' ')


(N, Q) = map(int, input().split())
ki = [[] for i in range(N + 1)]
val = [0 for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	ki[a].append(b)
	ki[b].append(a)
for _ in range(Q):
	(p, x) = map(int, input().split())
	val[p] += x
q = [(1, 0)]
while q:
	(c, p) = q.pop()
	val[c] += val[p]
	for x in ki[c]:
		if x == p:
			continue
		q.append((x, c))
print(' '.join(map(str, val[1:])))


(N, Q) = map(int, input().split())
List_ab = [list(map(int, input().split())) for i in range(N - 1)]
List_px = [list(map(int, input().split())) for i in range(Q)]
count_list = [0] * N
List_ab.sort()
for i in range(Q):
	count_list[List_px[i][0] - 1] += List_px[i][1]
for i in range(N - 1):
	count_list[List_ab[i][1] - 1] += count_list[List_ab[i][0] - 1]
print(*count_list)


import sys
sys.setrecursionlimit(10 ** 7)
input = lambda : sys.stdin.readline()
(N, Q) = map(int, input().split())
ab = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	ab[a - 1].append(b)
	ab[b - 1].append(a)
P = [0 for _ in range(N)]
for i in range(Q):
	(p, x) = map(int, input().split())
	P[p - 1] += x

def dfs(p, par):
	for i in ab[p - 1]:
		if i != par:
			P[i - 1] += P[p - 1]
			dfs(i, p)
dfs(1, -12345)
print(' '.join(map(str, P)))


f = lambda : map(int, input().split())
(n, q) = f()
g = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
c = [0] * n
for i in range(q):
	(v, x) = f()
	c[v - 1] += x
b = [1] * n
s = [0]
b[0] = 0
while s:
	t = s.pop()
	for i in g[t]:
		if b[i]:
			c[i] += c[t]
			s += [i]
			b[i] = 0
print(*c)


(N, Q) = map(int, input().split())
tree = [[] for _ in range(N)]
result = [0] * N
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	tree[a - 1].append(b)
for _ in range(Q):
	(p, x) = map(int, input().split())
	result[p - 1] += x
for i in range(N - 1):
	for j in tree[i]:
		result[j - 1] += result[i]
print(' '.join(map(str, result)))


(n, q) = list(map(int, input().split()))
e = [[] for _ in range(n)]
v = [0] * n
for _ in range(n - 1):
	x = list(map(int, input().split()))
	e[x[0] - 1].append(x[1] - 1)
for _ in range(q):
	x = list(map(int, input().split()))
	v[x[0] - 1] += x[1]
for (i, x) in enumerate(e):
	for j in x:
		v[j] += v[i]
for x in v:
	print(x, end=' ')


(n, q) = map(int, input().split())
neighbor = [[] for _ in range(n + 1)]
ans = [0] * (n + 1)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	neighbor[a].append(b)
	neighbor[b].append(a)
for _ in range(q):
	(p, x) = map(int, input().split())
	ans[p] += x
visit = [True] * (n + 1)
tmp = [1]
for x in tmp:
	visit[x] = False
	for y in neighbor[x]:
		if visit[y]:
			tmp.append(y)
			ans[y] += ans[x]
print(*ans[1:])


(n, q) = map(int, input().split())
parents = [set() for _ in range(n)]
nodes = [0 for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	parents[b - 1].add(a - 1)
for _ in range(q):
	(i, k) = map(int, input().split())
	nodes[i - 1] += k
for (i, p) in enumerate(parents):
	nodes[i] += sum([nodes[j] for j in p])
print(*nodes)


(n, q) = map(int, input().split())
e = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	e[a].append(b)
	e[b].append(a)
ps = [0 for i in range(n)]
for i in range(q):
	(p, x) = map(int, input().split())
	ps[p - 1] += x
s = [-1 for i in range(n)]
sc = [0]
s[0] = 0
while sc:
	nsc = []
	for i in sc:
		s[i] += ps[i]
		for j in e[i]:
			if s[j] == -1:
				nsc.append(j)
				s[j] = s[i]
	sc = nsc
r = ''
for i in range(n):
	r += str(s[i]) + ' '
print(r[:-1])


(N, Q) = map(int, input().split())
value = [0] * (N + 1)
ab_list = []
for i in range(N - 1):
	(a, b) = map(int, input().split())
	ab_list.append([a, b])
ab_list.sort(key=lambda x: x[0])
for i in range(Q):
	(p, q) = map(int, input().split())
	value[p] += q
for (a, b) in ab_list:
	value[b] += value[a]
print(' '.join(map(str, value[1:])))


(N, Q) = map(int, input().split())
f = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	f[a - 1].append(b - 1)
	f[b - 1].append(a - 1)
ans = [0] * N
for i in range(Q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
from collections import deque
d = deque()
d.append(0)
root = [-1] * N
root[0] = 0
while len(d) > 0:
	z = d.popleft()
	for i in f[z]:
		if root[i] == -1:
			root[i] = z
			ans[i] += ans[z]
			d.append(i)
print(*ans)


(n, q) = map(int, input().split())
c = [0] * (n + 1)
parent = [0] * (n + 1)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	parent[b] = a
for _ in range(q):
	(p, x) = map(int, input().split())
	c[p] += x
for i in range(2, n + 1):
	c[i] += c[parent[i]]
print(' '.join(map(str, c[1:])))


(n, q) = (int(_) for _ in input().split())
res = [0] * n
l = [[] for i in range(n - 1)]
for i in range(n - 1):
	(a, b) = (int(_) for _ in input().split())
	l[a - 1].append(b)
p = [list(map(int, input().split())) for i in range(q)]
for i in p:
	res[i[0] - 1] += i[1]
for i in range(n - 1):
	for ii in l[i]:
		res[ii - 1] += res[i]
[print(i, end=' ') for i in res]
print()


(n, q) = map(int, input().split())
ki = [[] for i in range(n + 1)]
c = [0] * (n + 1)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	ki[a].append(b)
for i in range(q):
	(p, x) = map(int, input().split())
	c[p] += x
st = [1]
while st:
	tmp = st.pop()
	for i in ki[tmp]:
		c[i] += c[tmp]
	st += ki[tmp]
print(*c[1:])


import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
ab = [None] * (N - 1)
for i in range(N - 1):
	ab[i] = list(map(int, input().split()))
ab = sorted(ab, key=lambda x: (x[0], x[1]))
px_n = [0] * N
for i in range(Q):
	(p, x) = list(map(int, input().split()))
	px_n[p - 1] += x
ans = [0] * N
ans[0] = px_n[0]
for (a, b) in ab:
	ans[b - 1] += ans[a - 1] + px_n[b - 1]
print(*ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
(n, q) = map(int, input().split())
t = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	t[a].append(b)
	t[b].append(a)
cnt = [0] * (n + 1)
for _ in range(q):
	(p, x) = map(int, input().split())
	cnt[p] += x

def csum(now, bef):
	for i in t[now]:
		if i != bef:
			cnt[i] += cnt[now]
			csum(i, now)
csum(1, 0)
print(*cnt[1:])


import sys
sys.setrecursionlimit(10 ** 7)
(n, q) = map(int, input().split())
edge = [[] for _ in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	edge[x - 1].append(y - 1)
	edge[y - 1].append(x - 1)
ans = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x

def dfs(c, p):
	for i in edge[c]:
		if i == p:
			continue
		ans[i] += ans[c]
		dfs(i, c)
dfs(0, -1)
print(*ans)


import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
(N, Q) = map(int, input().split())
T = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	T[a - 1].append(b - 1)
	T[b - 1].append(a - 1)
O = [0 for i in range(N)]
for i in range(Q):
	(p, x) = map(int, input().split())
	O[p - 1] += x

def dfs(n, r):
	for i in T[n]:
		if i != r:
			O[i] += O[n]
			dfs(i, n)
dfs(0, -1)
print(*O)


(N, Q) = map(int, input().split())
arr_ab = [[] for j in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	arr_ab[a - 1].extend([b])
arr_px = [0] * N
for _ in range(Q):
	(p, x) = map(int, input().split())
	arr_px[p - 1] += x
ans = [0] * N
for i in range(N - 1):
	for j in arr_ab[i]:
		arr_px[j - 1] += arr_px[i]
print(' '.join(list(map(str, arr_px))))


(n, q) = list(map(int, input().split()))
edge = []
for i in range(n - 1):
	(tempa, tempb) = list(map(int, input().split()))
	edge.append((tempa - 1, tempb - 1))
node = [0] * n
for i in range(q):
	(p, x) = list(map(int, input().split()))
	node[p - 1] += x
edge.sort()
for e in edge:
	node[e[1]] += node[e[0]]
for n in node:
	print(n)


def o():
	return map(int, input().split())
(n, q) = o()
a = [[] for i in range(n)]
x = [0] * n
for i in range(n - 1):
	(u, v) = o()
	a[u - 1] += [v - 1]
	a[v - 1] += [u - 1]
for i in range(q):
	(u, v) = o()
	x[u - 1] += v
p = [[0, 0]]
s = 0
while p:
	(r, s) = p.pop()
	for i in a[r]:
		if i != s:
			p += [[i, r]]
			x[i] += x[r]
print(*x)


(N, Q) = map(int, input().split())
root = []
counter = [0] * N
ans = [0] * N
for i in range(N - 1):
	(a, b) = map(int, input().split())
	root.append([a, b])
root.sort(key=lambda x: x[1])
for j in range(Q):
	(p, x) = map(int, input().split())
	counter[p - 1] += x
ans[0] = counter[0]
for k in range(1, N):
	ans[k] = counter[k] + ans[root[k - 1][0] - 1]
print(*list(ans))


import sys
sys.setrecursionlimit(10 ** 9)
(N, Q) = map(int, input().split())
T = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	T[a].append(b)
	T[b].append(a)
V = [0] * N
for _ in range(Q):
	(p, x) = map(int, input().split())
	V[p - 1] += x

def dfs(now, prev=-1):
	for next in T[now]:
		if next != prev:
			V[next] += V[now]
			dfs(next, now)
dfs(0)
print(*V)


(n, q) = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(n - 1)]
ab_list = sorted(ab_list)
ans = [0 for i in range(n)]
for i in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
for ab in ab_list:
	ans[ab[1] - 1] += ans[ab[0] - 1]
print(*ans)


(n, q) = map(int, input().split())
A = [set([]) for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	A[a].add(b)
C = [0] * (n + 1)
for _ in range(q):
	(p, x) = map(int, input().split())
	C[p] += x
for i in range(1, n + 1):
	c = C[i]
	for a in A[i]:
		C[a] += c
print(*C[1:])


(n, q) = map(int, input().split())
link = dict()
counter = list([0] * n)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	link[b - 1] = a - 1
for i in range(q):
	(p, pp) = map(int, input().split())
	counter[p - 1] += pp
for i in range(n):
	if i in link:
		counter[i] += counter[link[i]]
counter = map(str, counter)
ans = ' '.join(counter)
print(ans)


from collections import deque

def main():
	(n, q) = map(int, input().split())
	node = [[] * n for i in range(n)]
	for i in range(n - 1):
		(a, b) = map(lambda x: int(x) - 1, input().split())
		node[b].append(a)
		node[a].append(b)
	ans = [0] * n
	for i in range(q):
		(p, x) = map(int, input().split())
		p -= 1
		ans[p] += x
	root = [0] * n
	edge = [[] * n for i in range(n)]
	root[0] = 0
	q = deque([0])
	visited = [False] * n
	visited[0] = True
	while q:
		r = q.popleft()
		for e in node[r]:
			if not visited[e]:
				visited[e] = True
				q.append(e)
				root[e] = r
				edge[r].append(e)
	p = [0] * n
	q = deque(edge[0])
	visited = [False] * n
	while q:
		e = q.popleft()
		p[e] = p[root[e]] + 1
		for e2 in edge[e]:
			if not visited[e2]:
				visited[e2] = True
				q.append(e2)
	p = sorted(enumerate(p), key=lambda x: x[1])
	for i in range(1, n):
		e = p[i][0]
		r = root[e]
		ans[e] += ans[r]
	print(*ans, sep=' ')

def __starting_point():
	main()
__starting_point()


import sys
from operator import itemgetter
(n, q) = [int(x) for x in sys.stdin.readline().strip().split()]
edge = [[] for _ in range(n - 1)]
for i in range(n - 1):
	edge[i] = [int(x) - 1 for x in sys.stdin.readline().strip().split()]
edge.sort(key=itemgetter(0))
c = [0 for _ in range(n)]
for i in range(q):
	(p, x) = [int(x) for x in sys.stdin.readline().strip().split()]
	c[p - 1] += x
for (a, b) in edge:
	c[b] += c[a]
print(*c)


import collections
(n, q) = map(int, input().split())
a = sorted(list((list(map(int, input().split())) for i in range(n - 1))))
p = collections.defaultdict(int)
for i in range(q):
	(k, v) = map(int, input().split())
	p[k] += v
li = [0] * n
li[0] += p[1]
for i in range(n - 1):
	li[a[i][1] - 1] += li[a[i][0] - 1] + p[a[i][1]]
print(*li)


def solve():
	cnt = [0] * int(2 * 100000.0 + 10)
	li = []
	(n, q) = map(int, input().split())
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		li.append((a, b))
	for _ in range(q):
		(p, x) = map(int, input().split())
		cnt[p] += x
	for (a, b) in sorted(li):
		cnt[b] += cnt[a]
	print(*cnt[1:n + 1])
solve()


(n, q) = map(int, input().split())
values = [0] * (n + 1)
parents = [0] * (n + 1)
results = [0] * (n + 1)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	parents[b] = a
for _ in range(q):
	(p, x) = map(int, input().split())
	values[p] += x
for i in range(1, n + 1):
	results[i] = values[i]
	if parents[i] != 0:
		results[i] += results[parents[i]]
print(*[results[i] for i in range(1, n + 1)])


import sys
sys.setrecursionlimit(10 ** 8)
(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
t = dict()
for i in range(1, n + 1):
	t[i] = set()
for (a, b) in ab:
	t[a].add(b)
	t[b].add(a)
cnt = [0] * n
s = set()
for (p, x) in px:
	cnt[p - 1] += x

def solve(p):
	s.add(p)
	for c in t[p]:
		if c not in s:
			cnt[c - 1] += cnt[p - 1]
			solve(c)
solve(1)
print(*cnt, sep=' ')


(N, Q) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N - 1)]
P = [list(map(int, input().split())) for _ in range(Q)]
G = [[] for _ in range(N + 1)]
X = [0] * (N + 1)
for (a, b) in L:
	G[a].append(b)
for (p, x) in P:
	X[p] += x
for (a, A) in enumerate(G):
	for b in A:
		X[b] += X[a]
print(' '.join(map(str, X[1:])))


(N, Q) = map(int, input().split())
ab = []
for i in range(N - 1):
	(a, b) = map(int, input().split())
	ab.append((a, b))
ab = sorted(ab, key=lambda x: x[0])
P = [0 for _ in range(N)]
for i in range(Q):
	(p, x) = map(int, input().split())
	P[p - 1] += x
for i in range(N - 1):
	(a, b) = ab[i]
	P[b - 1] += P[a - 1]
print(*P)


from operator import itemgetter
(n, q) = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n - 1)]
pxpx = [list(map(int, input().split())) for _ in range(q)]
abab.sort(key=itemgetter(0))
ans = [0 for _ in range(n)]
for (p, x) in pxpx:
	ans[p - 1] += x
for (a, b) in abab:
	ans[b - 1] += ans[a - 1]
print(*ans)


from collections import deque
(n, q) = map(int, input().split())
z = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	z[a].append(b)
	z[b].append(a)
l = [list(map(int, input().split())) for i in range(q)]
(p, x) = [list(i) for i in zip(*l)]
c = [0] * n
for i in range(q):
	c[p[i] - 1] += x[i]
queue = deque([1])
check = [1] * (n + 1)
while queue:
	p = queue.popleft()
	if check[p]:
		for i in z[p]:
			if check[i]:
				c[i - 1] += c[p - 1]
				queue.append(i)
	check[p] = 0
print(' '.join(map(str, c)))


import sys
sys.setrecursionlimit(10 ** 8)
(N, Q) = map(int, input().split())
g = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = list(map(int, input().split()))
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
cnt = [0] * N
for i in range(Q):
	(p, x) = list(map(int, input().split()))
	cnt[p - 1] += x

def dfs(g, v):
	for nv in g[v]:
		if ans_cnt[nv] != -1:
			continue
		ans_cnt[nv] = cnt[nv] + ans_cnt[v]
		dfs(g, nv)
ans_cnt = [-1] * N
ans_cnt[0] = cnt[0]
dfs(g, 0)
for (i, value) in enumerate(ans_cnt):
	print(value, end='')
	if i != len(ans_cnt) - 1:
		print(' ', end='')
print()


from collections import deque
(n, q) = map(int, input().split())
E = [[] for _ in range(n)]
P = [0] * n
V = [False] * n
for i in range(n - 1):
	(a, b) = map(int, input().split())
	E[a - 1].append(b - 1)
	E[b - 1].append(a - 1)
for i in range(q):
	(p, x) = map(int, input().split())
	P[p - 1] += x
que = deque([0])
while que:
	s = que.popleft()
	V[s] = True
	for ni in E[s]:
		if V[ni] == False:
			P[ni] += P[s]
			que.append(ni)
print(*P)


import sys
f = lambda : map(int, sys.stdin.readline().split())
(n, q) = f()
g = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
c = [0] * n
for i in range(q):
	(v, x) = f()
	c[v - 1] += x
b = [0] + [1] * (n - 1)
s = [0]
while s:
	t = s.pop()
	for i in g[t]:
		if b[i]:
			c[i] += c[t]
			s += [i]
			b[i] = 0
print(*c)


(N, Q) = map(int, input().split())
d = [0 for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	d[b] = a
ans = [0 for i in range(N)]
for i in range(Q):
	(p, x) = map(int, input().split())
	p -= 1
	ans[p] += x
for i in range(1, N):
	ans[i] += ans[d[i]]
print(*ans)


import collections
(N, Q) = map(int, input().split())
lski = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	lski[a].append(b)
	lski[b].append(a)
countercost = collections.Counter()
for i in range(Q):
	(p, x) = map(int, input().split())
	countercost[p] += x
dist = [-1] * (N + 1)
parent = [-1] * (N + 1)
dist[0] = 0
dist[1] = countercost[1]
d = collections.deque()
d.append(1)
while d:
	v = d.popleft()
	for i in lski[v]:
		if parent[a] == b:
			continue
		if dist[i] != -1:
			continue
		parent[b] = a
		dist[i] = dist[v] + countercost[i]
		d.append(i)
dist.pop(0)
ansls = [str(i) for i in dist]
print(' '.join(ansls))


from collections import deque
(N, Q) = map(int, input().split())
(g, q, s, c, d) = ([[] for i in range(N)], [0] * N, [False] * N, [0] * N, deque())
for _ in range(N - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	g[a].append(b)
	g[b].append(a)
for _ in range(Q):
	(p, x) = map(int, input().split())
	q[p - 1] += x
d.append(0)
while d:
	v = d.popleft()
	s[v] = True
	for x in g[v]:
		if not s[x]:
			d.append(x)
			q[x] += q[v]
print(' '.join(map(str, q)))


import sys
sys.setrecursionlimit(10 ** 6)
stdin = sys.stdin
na = lambda : map(int, stdin.readline().split())
(N, Q) = na()
ans = [0] * N
g = [[] for _ in range(N)]

def dfs(cur, par):
	for e in g[cur]:
		if e == par:
			continue
		ans[e] += ans[cur]
		dfs(e, cur)
for _ in range(N - 1):
	(a, b) = na()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
for _ in range(Q):
	(p, x) = na()
	ans[p - 1] += x
dfs(0, -1)
print(*ans)


(n, q) = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
base_score = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	base_score[p - 1] += x
score = [0] * n
for (i, bs) in enumerate(base_score):
	score[i] = bs
	for j in edge[i]:
		base_score[j] += bs
print(*score)


(n, q, *t) = map(int, open(0).read().split())
s = [0]
d = s * n
f = s + [1] * n
e = [[] for _ in d]
for (a, b) in zip(*[iter(t[:-q - q])] * 2):
	e[a - 1] += (b - 1,)
	e[b - 1] += (a - 1,)
for (p, x) in zip(*[iter(t[-q - q:])] * 2):
	d[p - 1] += x
while s:
	v = s.pop()
	for w in e[v]:
		d[w] += d[v] * f[w]
		s += [w] * f[w]
		f[w] = 0
print(*d)


(N, Q) = map(int, input().split())
parentNodes = [1] * (N + 1)
ans = [0] * (N + 1)
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	parentNodes[b] = a
for _ in range(Q):
	(p, x) = map(int, input().split())
	ans[p] += x
for i in range(2, N + 1):
	ans[i] += ans[parentNodes[i]]
ans.pop(0)
print(' '.join(map(str, ans)))


i = lambda : map(int, input().split())
(N, Q) = i()
adj = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = i()
	adj[a - 1].append(b - 1)
	adj[b - 1].append(a - 1)
V = [0 for _ in range(N)]
for _ in range(Q):
	(p, x) = i()
	V[p - 1] += x
par = [-1 for _ in range(N)]
q = [0]
for cur in q:
	if par[cur] != -1:
		V[cur] += V[par[cur]]
	for nxt in adj[cur]:
		if nxt == par[cur]:
			continue
		par[nxt] = cur
		q.append(nxt)
print(' '.join(map(str, V)))


from collections import defaultdict
(N, Q) = map(int, input().split())
parent = defaultdict(list)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	parent[b] = a
values = [0] * (N + 1)
for i in range(Q):
	(p, x) = map(int, input().split())
	values[p] += x
for i in range(2, N + 1):
	values[i] += values[parent[i]]
values = map(str, values[1:])
print(' '.join(values))


(N, Q) = map(int, input().split())
l = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	l[a - 1].append(b - 1)
	l[b - 1].append(a - 1)
used = [False] * N
r = [0] * N
for i in range(Q):
	(p, x) = map(int, input().split())
	r[p - 1] += x
stack = [0]
while stack:
	i = stack.pop()
	used[i] = True
	for to in l[i]:
		if not used[to]:
			stack.append(to)
			r[to] += r[i]
print(*r)


(n, q) = map(int, input().split())
l = [0 for i in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	l[b - 1] = a - 1
ans = [0 for _ in range(n)]
p = [list(map(int, input().split())) for i in range(q)]
for p1 in p:
	ans[p1[0] - 1] += p1[1]
for i in range(1, n):
	ans[i] += ans[l[i]]
print(' '.join(map(str, ans)))


I = lambda : map(int, input().split())
(n, q) = I()
e = [[] for _ in range(n)]
d = [0] * n
for _ in range(n - 1):
	(a, b) = I()
	e[a - 1] += (b - 1,)
	e[b - 1] += (a - 1,)
for _ in range(q):
	(p, x) = I()
	d[p - 1] += x
f = [1] + [0] * n
q = [0]
while q:
	v = q.pop()
	for w in e[v]:
		if f[w]:
			continue
		f[w] = 1
		d[w] += d[v]
		q += (w,)
print(*d)


from collections import deque
(n, q) = map(int, input().split())
tr = [[] for i in range(n)]
for i in range(n - 1):
	(b, c) = map(int, input().split())
	tr[b - 1].append(c - 1)
	tr[c - 1].append(b - 1)
a = [0] * n
for i in range(q):
	(b, c) = map(int, input().split())
	a[b - 1] += c
d = deque([0])
f = [0] * n
f[0] = 1
while d:
	p = d.pop()
	f[p] = 1
	for c in tr[p]:
		if f[c] == 1:
			continue
		a[c] += a[p]
		d.append(c)
print(*a)


(N, Q) = map(int, input().split())
tree = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	tree[a - 1].extend([b])
nodes = [0] * N
for _ in range(Q):
	(p, x) = map(int, input().split())
	nodes[p - 1] += x
for i in range(N - 1):
	for j in tree[i]:
		nodes[j - 1] += nodes[i]
print(' '.join(list(map(str, nodes))))


(n, q) = map(int, input().split())
lis = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	lis[a - 1].append(b)
kotae = [0] * n
c_list = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	c_list[p - 1] += x
for i in range(len(lis)):
	kotae[i - 1] += c_list[i - 1]
	for m in lis[i - 1]:
		kotae[m - 1] += kotae[i - 1]
for i in kotae:
	print(i, end=' ')
print()


(n, q) = (int(num) for num in input().split())
par = [n] * n
visited = [0] * n
val = [0] * n
ab = []
for i in range(n - 1):
	(a, b) = (int(num) - 1 for num in input().split())
	par[b] = a
for _ in range(q):
	(p, x) = (int(num) for num in input().split())
	p -= 1
	val[p] += x
for i in range(1, n):
	val[i] += val[par[i]]
ans = ''
for num in val:
	ans += str(num) + ' '
print(ans)


from collections import deque
(N, Q) = list(map(int, input().split()))
t = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = list(map(int, input().split()))
	t[a].append(b)
	t[b].append(a)
score = [0] * (N + 1)
for i in range(Q):
	(p, x) = list(map(int, input().split()))
	score[p] += x
is_read = [False] * (N + 1)
d = deque()
d.append(1)
while len(d) != 0:
	now = d.popleft()
	is_read[now] = True
	for c in t[now]:
		if is_read[c]:
			continue
		score[c] += score[now]
		d.append(c)
print(' '.join(map(str, score[1:])))


import sys
sys.setrecursionlimit(10 ** 6)

def MI():
	return map(int, input().split())
(N, Q) = MI()
graph = [[] for i in range(N)]
for i in range(1, N):
	(a, b) = MI()
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
point = [0] * N
for i in range(Q):
	(p, x) = MI()
	point[p - 1] += x

def dfs(now, pre=-1):
	for next in graph[now]:
		if next == pre:
			continue
		point[next] += point[now]
		dfs(next, now)
dfs(0)
print(*point)


(n, q) = map(int, input().split())
tree = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a].append(b)
op = [0] * (n + 1)
for i in range(q):
	(p, x) = map(int, input().split())
	op[p] += x
for (root, reaf) in enumerate(tree):
	for i in reaf:
		op[i] += op[root]
print(*op[1:])


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
l = [[] for i in range(n + 1)]
for (a, b) in ab:
	l[a].append(b)
value = [0 for i in range(n + 1)]
for (p, x) in px:
	value[p] += x
stack = [1]
while stack:
	label = stack.pop()
	for i in l[label]:
		value[i] += value[label]
	stack += l[label]
print(*value[1:])


import sys
sys.setrecursionlimit(10000000)

def main():
	(n, q) = list(map(int, input().split()))
	Ki = [[] for i in range(n)]
	for _ in range(n - 1):
		(a, b) = list(map(int, input().split()))
		Ki[a - 1] += [b - 1]
		Ki[b - 1] += [a - 1]
	ans = [0] * n
	for _ in range(q):
		(p, x) = list(map(int, input().split()))
		ans[p - 1] += x

	def add(N=0, L=-1):
		for k in Ki[N]:
			if k != L:
				ans[k] += ans[N]
				add(k, N)
	add()
	print(' '.join([str(a) for a in ans]))

def __starting_point():
	main()
__starting_point()


(N, Q) = map(int, input().split())
ct = [0] * N
edges = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	edges[a - 1].append(b - 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	ct[p - 1] += x
ans = [0] * N
ans[0] = ct[0]
q = [(0, ct[0])]
while len(q):
	(i, c) = q.pop()
	for t in edges[i]:
		ans[t] = c + ct[t]
		q.append((t, ans[t]))
print(' '.join(map(str, ans)))


(N, Q) = map(int, input().split())
node_lst = [list(map(int, input().split())) for i in range(N - 1)]
ope_lst = [list(map(int, input().split())) for i in range(Q)]
cnt_lst = [0 for i in range(N)]
for ope in ope_lst:
	(p, x) = (ope[0], ope[1])
	cnt_lst[p - 1] += x
node_lst = sorted(node_lst, key=lambda x: x[0])
for l in node_lst:
	(src, dst) = (l[0] - 1, l[1] - 1)
	cnt_lst[dst] += cnt_lst[src]
print(' '.join([str(c) for c in cnt_lst]))


import sys
sys.setrecursionlimit(10 ** 9)
(n, q) = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
S = [0] * (n + 1)
for _ in range(q):
	(p, x) = map(int, input().split())
	S[p] += x

def dfs(now, prev=-1):
	for next in G[now]:
		if next == prev:
			continue
		S[next] += S[now]
		dfs(next, now)
dfs(1)
print(*S[1:])


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
pq = [list(map(int, input().split())) for _ in range(m)]
ab2 = sorted(ab, key=lambda x: x[0])
pq2 = sorted(pq, key=lambda x: x[0])
res = [0 for _ in range(n)]
for (p, q) in pq2:
	res[p - 1] += q
for (a, b) in ab2:
	res[b - 1] += res[a - 1]
ans = str(res[0])
for i in range(1, n):
	ans += ' ' + str(res[i])
print(ans)


import sys
sys.setrecursionlimit(10 ** 6 + 1000)
words = lambda t: list(map(t, input().split()))
(n, q) = words(int)
par = [0] * n
for i in range(n - 1):
	(a, b) = words(int)
	par[b - 1] = a - 1
points = [0] * n
for i in range(q):
	(p, x) = words(int)
	points[p - 1] += x
ans = [0] * n
ans[0] = points[0]
for i in range(1, n):
	ans[i] = ans[par[i]] + points[i]
print(' '.join(map(str, ans)))


import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)
(N, Q) = map(int, input().split())
T = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	T[a].append(b)
	T[b].append(a)
V = [0] * (N + 1)
for q in range(Q):
	(p, x) = map(int, input().split())
	V[p] += x

@lru_cache(maxsize=None)
def dfs(i, parent, acc):
	V[i] += acc
	for j in T[i]:
		if j != parent:
			dfs(j, i, V[i])
(cur, parent, acc) = (1, 0, 0)
dfs(cur, parent, acc)
print(*V[1:])


import sys
sys.setrecursionlimit(10 ** 6)

def MI():
	return map(int, input().split())
(N, Q) = MI()
Edge = [[] for _ in range(N)]
Point = [0] * N
for i in range(N - 1):
	(a, b) = MI()
	Edge[a - 1].append(b - 1)
	Edge[b - 1].append(a - 1)
for i in range(Q):
	(p, x) = MI()
	Point[p - 1] += x

def dfs(now, pre=-1):
	for nxt in Edge[now]:
		if nxt == pre:
			continue
		Point[nxt] += Point[now]
		dfs(nxt, now)
dfs(0)
print(*Point)


f = lambda : map(int, input().split())
(n, k) = f()
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
l = [0] * n
for _ in range(k):
	(p, x) = f()
	l[p - 1] += x
u = [0] * n
q = [0]
while q:
	v = q.pop()
	u[v] = 1
	for c in g[v]:
		if u[c]:
			continue
		l[c] += l[v]
		q += [c]
print(*l)


from collections import deque
(N, Q) = map(int, input().split())
V = [0] * N
E = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	E[a - 1].append(b - 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	V[p - 1] += x
stack = deque()
stack.append(0)
ans = [0] * N
ans = V
while stack:
	v = stack.popleft()
	for e in E[v]:
		ans[e] += ans[v]
		stack.append(e)
print(*ans)


from operator import itemgetter
(n, q) = map(int, input().split())
a = []
s = [0]
for i in range(n - 1):
	a.append([int(j) for j in input().split()])
	s.append(0)
a.sort(key=itemgetter(0))
for i in range(0, q):
	(P, X) = map(int, input().split())
	s[P - 1] = s[P - 1] + X
for j in range(0, n - 1):
	s[a[j][1] - 1] = s[a[j][1] - 1] + s[a[j][0] - 1]
print(' '.join(map(str, s)))


(N, Q) = map(int, input().split())
C = [[] for _ in range(N + 1)]
V = set([])
R = [0] * (N + 1)
for i in range(N - 1):
	(a, b) = map(int, input().split())
	C[a].append(b)
	C[b].append(a)
for i in range(Q):
	(a, b) = map(int, input().split())
	R[a] += b
from collections import deque
q = deque([])
q.append(1)
while len(q) > 0:
	p = q.popleft()
	for i in C[p]:
		if not i in V:
			R[i] += R[p]
			q.append(i)
	V.add(p)
print(*R[1:])


import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
V = [0] * N
A = []
for i in range(N - 1):
	(a, b) = map(int, input().split())
	A.append((a, b))
A.sort()
P = []
for i in range(Q):
	(x, y) = map(int, input().split())
	P.append((x, y))
P.sort()
for p in P:
	V[p[0] - 1] += p[1]
for a in A:
	V[a[1] - 1] += V[a[0] - 1]
print(*V)


(n, q) = map(int, input().split())
cnt = [0 for _ in range(n)]
edge = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
for _ in range(q):
	(p, x) = map(int, input().split())
	cnt[p - 1] += x
for v in range(n):
	for u in edge[v]:
		cnt[u] += cnt[v]
print(' '.join([str(x) for x in cnt]))


(N, Q) = map(int, input().split())
edge = [[] for i in range(N)]
q = [0 for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b)
for i in range(Q):
	(a, v) = map(int, input().split())
	q[a - 1] += v
for (i, v) in enumerate(q):
	for j in edge[i]:
		q[j - 1] += v
print(*q)


import sys
from collections import Counter, deque, defaultdict
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.141592653589793

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

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return map(int, sys.stdin.readline().strip().split())

def read_ints2(x):
	return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())

def read_str_list():
	return list(sys.stdin.readline().strip().split())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def GCD(a: int, b: int) -> int:
	return b if a % b == 0 else GCD(b, a % b)

def LCM(a: int, b: int) -> int:
	return a * b // GCD(a, b)

def Main():
	(n, q) = read_ints()
	tree = [[] for _ in range(n)]
	c = [0] * n
	for _ in range(n - 1):
		(a, b) = read_ints()
		tree[~-a].append(~-b)
		tree[~-b].append(~-a)
	for _ in range(q):
		(p, x) = read_ints()
		c[~-p] += x
	que = deque([0])
	seen = [False] * n
	while que:
		p = que.pop()
		seen[p] = True
		for x in tree[p]:
			if seen[x]:
				continue
			que.append(x)
			c[x] += c[p]
	print(*c)

def __starting_point():
	Main()
__starting_point()


(n, q) = map(int, input().split())
c = [0 for i in range(n)]
tree = sorted([list(map(int, input().split())) for i in range(n - 1)])
for j in range(q):
	(p, x) = map(int, input().split())
	c[p - 1] += x
for i in range(n - 1):
	c[tree[i][1] - 1] += c[tree[i][0] - 1]
for i in range(n):
	c[i] = str(c[i])
print(' '.join(c))


(N, Q) = map(int, input().split())
G = [[] for n in range(N)]
ans = N * [0]
for n in range(N - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
for q in range(Q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
f = N * [1]
t = [0]
while t:
	v = t.pop()
	f[v] = 0
	for k in G[v]:
		if f[k]:
			ans[k] += ans[v]
			t.append(k)
print(*ans)


import sys
readline = sys.stdin.readline
(N, Q) = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, readline().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
point = [0] * N
for i in range(Q):
	(p, x) = map(int, readline().split())
	point[p - 1] += x
stack = [(0, -1, 0)]
while stack:
	(v, parent, p) = stack.pop()
	point[v] += p
	p = point[v]
	for child in G[v]:
		if child == parent:
			continue
		stack.append([child, v, p])
print(*point)


(N, Q) = map(int, input().split())
tree_data = [tuple(map(int, input().split())) for i in range(N - 1)]
operation = [tuple(map(int, input().split())) for i in range(Q)]
tree_data = sorted(tree_data)
node = dict(zip(range(1, N + 1), [0] * N))
for o in operation:
	node[o[0]] += o[1]
for n in tree_data:
	node[n[1]] += node[n[0]]
print(' '.join(map(str, node.values())))


import sys
sys.setrecursionlimit(10 ** 7)
(N, Q) = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
lst = []
for _ in range(Q):
	(P, X) = map(int, input().split())
	P -= 1
	lst.append((P, X))
cnt = [0] * N
for (p, x) in lst:
	cnt[p] += x
seen = [False] * N

def dfs(v):
	seen[v] = True
	for next_v in G[v]:
		if seen[next_v] == True:
			continue
		cnt[next_v] += cnt[v]
		dfs(next_v)
dfs(0)
print(*cnt)


from collections import defaultdict
(N, Q) = list(map(int, input().split()))
d = defaultdict(list)
for _ in range(N - 1):
	(a, b) = list(map(int, input().split()))
	d[a].append(b)
	d[b].append(a)
c = defaultdict(int)
for _ in range(Q):
	(p, x) = list(map(int, input().split()))
	c[p] += x
ans = [0 for i in range(N)]
que = [(1, 0, -1)]
while len(que) > 0:
	tmp = []
	for (v, x, par) in que:
		x += c[v]
		ans[v - 1] = str(x)
		for w in d[v]:
			if w != par:
				tmp.append((w, x, v))
	que = tmp
print(' '.join(ans))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def addc(p, b):
	for i in e[p]:
		if i == b:
			continue
		c[i] += c[p]
		addc(i, p)
(n, q) = map(int, input().split())
e = [[] for i in range(n + 1)]
c = [0] * (n + 1)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	e[a].append(b)
	e[b].append(a)
for i in range(q):
	(p, x) = map(int, input().split())
	c[p] += x
addc(1, -1)
print(*c[1:])


(N, Q) = map(int, input().split())
AB = [[] for i in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	AB[a].append(b)
X = [0] * (N + 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	X[p] += x
S = [1]
while len(S) > 0:
	p = S.pop()
	for c in AB[p]:
		X[c] += X[p]
		S.append(c)
print(' '.join(map(str, X[1:])))


from collections import deque
(N, Q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]
tree = [[] for _ in range(N)]
for (a, b) in ab:
	tree[a - 1].append(b - 1)
	tree[b - 1].append(a - 1)
counter = [0] * N
for (p, x) in px:
	counter[p - 1] += x
flag = [1] * N
t = deque()
t.append(0)
while t:
	v = t.popleft()
	flag[v] = 0
	for i in tree[v]:
		if flag[i]:
			counter[i] += counter[v]
			t.append(i)
print(*counter)


(n, q) = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	edge[u].append(v)
cost = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	p -= 1
	cost[p] += x
for (idx, e) in enumerate(cost):
	if e == 0:
		continue
	for f in edge[idx]:
		cost[f] += e
print(*cost)


(n, q) = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b)
	g[b - 1].append(a)
x = [0] * n
for i in range(q):
	(p, X) = map(int, input().split())
	x[p - 1] += X
from collections import deque
d = deque()
d.append(0)
y = [0] * n
while len(d) >= 1:
	s = d.popleft()
	y[s] += 1
	for i in g[s]:
		if y[i - 1] != 1:
			d.append(i - 1)
			x[i - 1] += x[s]
print(*x)


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n - 1)]
px = [list(map(int, input().split())) for i in range(q)]
parent = [0] * n
ans = [0] * n
for i in ab:
	(a, b) = (i[0], i[1])
	parent[b - 1] = a - 1
for j in px:
	(p, x) = (j[0], j[1])
	ans[p - 1] += x
for (key, i) in enumerate(ans[1:]):
	key += 1
	ans[key] += ans[parent[key]]
print(*ans)


(N, Q) = map(int, input().split())
nodes = [0 for _ in range(N + 1)]
branches = []
for j in range(N - 1):
	(parent, child) = map(int, input().split())
	branches.append([parent, child])
for _ in range(Q):
	(parent, number) = map(int, input().split())
	nodes[parent] += number
branches.sort()
for branch in branches:
	parent = branch[0]
	child = branch[1]
	nodes[child] += nodes[parent]
print(*nodes[1:], sep=' ')


(n, q) = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
ans = [0] * n
for _ in range(q):
	(p, x) = map(int, input().split())
	ans[p - 1] += x
Q = [0]
visited = {0}
while Q:
	P = []
	for i in Q:
		for j in edge[i]:
			if j in visited:
				continue
			visited.add(j)
			ans[j] += ans[i]
			P.append(j)
	Q = P
print(*ans)


(N, Q) = map(int, input().split())
v = [[] for _ in range(N + 1)]
w = [0] * (N + 1)
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	v[a].append(b)
	v[b].append(a)
for j in range(Q):
	(p, x) = map(int, input().split())
	w[p] += x
q = [(1, 0)]
while q:
	(c, p) = q.pop()
	w[c] += w[p]
	for x in v[c]:
		if x == p:
			continue
		q.append((x, c))
print(' '.join([str(x) for x in w[1:]]))


import collections
(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
c = [[] for _ in range(n)]
for (a, b) in ab:
	(a, b) = (a - 1, b - 1)
	c[a].append(b)
	c[b].append(a)
point = [0] * n
for (p, x) in px:
	point[p - 1] += x
parents = [0] * n
ans = [0] * n
q = collections.deque()
q.append(0)
while q:
	v = q.pop()
	ans[v] = ans[parents[v]] + point[v]
	for i in c[v]:
		if i == parents[v]:
			continue
		parents[i] = v
		q.append(i)
print(' '.join(list(map(str, ans))))


(n, q) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
dp = [0] * n
ls = [[] for i in range(n)]
for i in ab:
	ls[i[0] - 1].append(i[1] - 1)
for i in px:
	dp[i[0] - 1] += i[1]
for i in range(n):
	for j in ls[i]:
		dp[j] += dp[i]
print(*dp)


(N, Q) = map(int, input().split())
parents = {1: 0}
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	(key, val) = (max(a, b), min(a, b))
	parents[key] = val
counts = [0] * (N + 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	counts[p] += x
results = [0] * (N + 2)
for i in range(1, N + 1):
	results[i] = counts[i] + results[parents[i]]
	print(results[i], end=' ')


(N, Q) = map(int, input().split())
to = [[] for _ in range(N + 1)]
ans = [0] * N
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	to[a].append(b)
	to[b].append(a)
for _ in range(Q):
	(pa, x) = map(int, input().split())
	pa -= 1
	ans[pa] += x
q = [(0, -1)]
while q:
	(v, p) = q.pop()
	for nv in to[v]:
		if nv == p:
			continue
		ans[nv] += ans[v]
		q.append((nv, v))
print(*ans)


(N, Q) = map(int, input().split())
childrens = [[] for i in range(0, N)]
for i in range(0, N - 1):
	(a, b) = map(int, input().split())
	childrens[a - 1].append(b - 1)
results = [0 for i in range(0, N)]
for i in range(0, Q):
	(p, x) = map(int, input().split())
	results[p - 1] += x
for i in range(0, N):
	for child in childrens[i]:
		results[child] += results[i]
print(' '.join(map(str, results)))


(n, q) = map(int, input().split())
g = [[] for _ in range(n)]
ans = [0] * n
for i in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
for j in range(q):
	(p, x) = list(map(int, input().split()))
	ans[p - 1] += x
f = [1] * n
t = [0]
while t:
	v = t.pop()
	f[v] = 0
	for k in g[v]:
		if f[k]:
			ans[k] += ans[v]
			t.append(k)
print(*ans)


from sys import stdin

def main():
	(N, Q) = map(int, input().split())
	AB = [tuple(map(int, input().split())) for _ in [0] * (N - 1)]
	PX = [tuple(map(int, input().split())) for _ in [0] * Q]
	AB.sort()
	point = [0] * (N + 1)
	for (p, x) in PX:
		point[p] += x
	for (a, b) in AB:
		point[b] += point[a]
	print(*point[1:])
input = lambda : stdin.readline()
main()


import sys
sys.setrecursionlimit(10 ** 6)
f = lambda : map(int, input().split())
(n, k) = f()
g = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
l = [0] * n
for _ in range(k):
	(p, x) = f()
	l[p - 1] += x

def dfs(v, p=-1):
	for c in g[v]:
		if c == p:
			continue
		l[c] += l[v]
		dfs(c, v)
dfs(0)
print(*l)


(n, q) = map(int, input().split())
sco = [0] * (n + 1)
edge = [[i] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[b].append(a)
for i in range(q):
	(p, x) = map(int, input().split())
	sco[p] += x
for i in range(1, n + 1):
	E = edge[i]
	for e in E:
		if e == i:
			continue
		sco[i] += sco[e]
print(*sco[1:])


import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)
(N, Q) = map(int, input().split())
T = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	T[a].append(b)
	T[b].append(a)
S = [0] * (N + 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	S[p] += x

@lru_cache(maxsize=None)
def dfs(now, prev=-1):
	for next in T[now]:
		if next == prev:
			continue
		S[next] += S[now]
		dfs(next, now)
dfs(1)
print(*S[1:])


import sys
input = sys.stdin.readline
from collections import deque
M = lambda : map(int, input().split())
(n, q) = M()
s = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = M()
	s[a - 1].append(b - 1)
	s[b - 1].append(a - 1)
p = [0] * n
for i in range(q):
	(a, b) = M()
	p[a - 1] += b
v = [1] + [0] * (n - 1)
d = deque([(0, 0)])
while d:
	(b, c) = d.popleft()
	c += p[b]
	p[b] = c
	for i in s[b]:
		if v[i]:
			continue
		v[i] = 1
		d.append((i, c))
print(*p)


from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

def dfs(now):
	seen[now] = True
	score[now] += operation[now]
	for next in branch[now]:
		if seen[next] is False:
			score[next] += score[now]
			dfs(next)
(N, Q) = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	branch[a - 1].add(b - 1)
	branch[b - 1].add(a - 1)
operation = [0] * N
for _ in range(Q):
	(p, x) = map(int, input().split())
	operation[p - 1] += x
seen = [False] * N
score = [0] * N
for i in range(N):
	if seen[i] is False:
		dfs(i)
for ans in score:
	print(ans, end=' ')


import sys
from collections import defaultdict
sys.setrecursionlimit(1000000)
(N, Q) = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	edges[a].append(b)
	edges[b].append(a)
d = defaultdict(int)
for _ in range(Q):
	(p, x) = map(int, input().split())
	d[p - 1] += x
visited = [False] * N
cnt = [0] * N

def dfs(n, acc):
	cnt[n] = acc
	for m in edges[n]:
		if not visited[m]:
			visited[m] = True
			dfs(m, acc + d[m])
visited[0] = True
dfs(0, d[0])
print(*cnt)


import sys
sys.setrecursionlimit(10 ** 9)
(N, Q) = map(int, input().split())
G = [[] for _ in range(N)]
counter = [0] * N
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
for _ in range(Q):
	(p, x) = map(int, input().split())
	counter[p - 1] += x
seen = [False] * N

def dfs(v, seen, G, counter):
	seen[v] = True
	for u in G[v]:
		if not seen[u]:
			counter[u] += counter[v]
			dfs(u, seen, G, counter)
dfs(0, seen, G, counter)
for c in counter:
	print(c, end=' ')
print('')


import sys
sys.setrecursionlimit(1000000)
s = sys.stdin.readlines()
(n, q) = map(int, s[0].split())
G = [[] * n for i in range(n)]
P = [0] * n
V = [0] * n
for e in s[1:n]:
	(a, b) = map(int, e.split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
for e in s[n:]:
	(c, d) = map(int, e.split())
	P[c - 1] += d

def dsf(i, p):
	V[i] = 1
	P[i] += p
	for j in G[i]:
		if V[j] != 1:
			dsf(j, P[i])
dsf(0, 0)
print(' '.join(map(str, P)))


(n, q) = map(int, input().split())
data = [[] for i in range(n + 1)]
counter = [0] * (n + 1)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	data[a].append(b)
	data[b].append(a)
for i in range(q):
	(p, x) = map(int, input().split())
	counter[p] += x
h = [1]
done = [0] * (n + 1)
while h:
	a = h.pop()
	for l in data[a]:
		if done[l] == 0:
			counter[l] += counter[a]
			h.append(l)
	done[a] = 1
print(*counter[1:])


(N, Q) = map(int, input().split())
nodes = [0 for _ in range(N)]
parents = {}
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	parents[b] = a
for _ in range(Q):
	(p, x) = map(int, input().split())
	nodes[p - 1] += x
for i in range(N):
	if i + 1 in parents:
		nodes[i] += nodes[parents[i + 1] - 1]
print(' '.join(map(str, nodes)))


(n, q) = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
c = [0] * n
for i in range(q):
	(p, x) = map(int, input().split())
	c[p - 1] += x
from collections import deque
visited = [-1] * n
q = deque()
q.append(0)
while q:
	cur = q.popleft()
	visited[cur] = 0
	for nx in G[cur]:
		if visited[nx] != -1:
			continue
		c[nx] += c[cur]
		q.append(nx)
print(*c)


import sys
sys.setrecursionlimit(500 * 500)
(N, Q) = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for edge in edges:
	tree[edge[0]].append(edge[1])
	tree[edge[1]].append(edge[0])
depth = [-1] * (N + 1)
depth[1] = 0
count = [0] * (N + 1)
for i in range(Q):
	(p, x) = map(int, input().split())
	count[p] += x

def dfs(tree, s):
	for l in tree[s]:
		if depth[l] == -1:
			depth[l] = 0
			count[l] += count[s]
			dfs(tree, l)
dfs(tree, 1)
for i in count[1:]:
	print(i, end=' ')