Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(x) for x in input().split()]
vs   = []
us   = [1]
xs   = None
	
for _ in range(0, n + 1):
	vs.append([])
	xs = [0] * (n + 1)

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if v not in us:
			xs[v] += x
			us.append(v)

print(" ".join(str(x) for x in xs[1:]))


Fixed submission:
n, q = [int(x) for x in input().split()]
vs   = []
	
for _ in range(0, n + 1):
	vs.append([])
	
xs    = [0]     * (n + 1)
fs    = [False] * (n + 1)
us    = [0]     * n
fs[1] = True
us[0] = 1
ui    = 0

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if fs[v] == False:
			xs[v] += x
			ui    += 1
			us[ui] = v
			fs[v]  = True

print(" ".join(str(x) for x in xs[1:]))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(x) for x in input().split()]
vs   = []
us   = [1]
xs   = None
fs   = None
	
for _ in range(0, n + 1):
	vs.append([])
	xs = [0]     * (n + 1)
	fs = [False] * (n + 1)

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
while 0 < len(us):
	u     = us.pop(0)
	x     = xs[u]
	fs[u] = True
	for n in vs[u]:
		if fs[n] == False:
			xs[n] += x
			us.append(n)

print(" ".join(str(x) for x in xs[1:]))


Fixed submission:
n, q = [int(x) for x in input().split()]
vs   = []
	
for _ in range(0, n + 1):
	vs.append([])
	
xs    = [0]     * (n + 1)
fs    = [False] * (n + 1)
us    = [0]     * n
fs[1] = True
us[0] = 1
ui    = 0

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if fs[v] == False:
			xs[v] += x
			ui    += 1
			us[ui] = v
			fs[v]  = True

print(" ".join(str(x) for x in xs[1:]))

Buggy python submission (verdict: Runtime Error):
n, q = [int(x) for x in input().split()]
vs   = []
xs   = []
	
for _ in range(0, n + 1):
	vs.append([])
	xs.append(0)

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
def calc(v, x, vs, xs):
	xs[v] += x
	for u in vs[v]:
		calc(u, xs[v], vs, xs)

calc(1, 0, vs, xs)

print(" ".join(str(x) for x in xs[1:]))


Fixed submission:
n, q = [int(x) for x in input().split()]
vs   = []
	
for _ in range(0, n + 1):
	vs.append([])
	
xs    = [0]     * (n + 1)
fs    = [False] * (n + 1)
us    = [0]     * n
fs[1] = True
us[0] = 1
ui    = 0

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if fs[v] == False:
			xs[v] += x
			ui    += 1
			us[ui] = v
			fs[v]  = True

print(" ".join(str(x) for x in xs[1:]))

Buggy python submission (verdict: Runtime Error):
n, q = [int(x) for x in input().split()]
ns   = []
vs   = []
ps   = []
xs   = []
	
for _ in range(0, n + 1):
	ns.append([])
	vs.append(0)

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	ns[a].append(b)
	
def calc(i, x, ns, vs):
	vs[i] += x
	for v in ns[i]:
		calc(v, x, ns, vs)

for _ in range(0, q):
	p, x = [int(x) for x in input().split()]
	calc(p, x, ns, vs)

print(" ".join(str(x) for x in vs[1:]))


Fixed submission:
n, q = [int(x) for x in input().split()]
vs   = []
	
for _ in range(0, n + 1):
	vs.append([])
	
xs    = [0]     * (n + 1)
fs    = [False] * (n + 1)
us    = [0]     * n
fs[1] = True
us[0] = 1
ui    = 0

for _ in range(0, n - 1):
	a, b = [int(x) for x in input().split()]
	vs[a].append(b)
	vs[b].append(a)

for _ in range(0, q):
	p, x   = [int(x) for x in input().split()]
	xs[p] += x
	
for i in range(0, n):
	x = xs[us[i]]
	for v in vs[us[i]]:
		if fs[v] == False:
			xs[v] += x
			ui    += 1
			us[ui] = v
			fs[v]  = True

print(" ".join(str(x) for x in xs[1:]))