Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())
# n, q = 3, 2
# arr = [(1, 3), (2, 3)]

graph = defaultdict(list)
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	# x, y = arr[i]
	graph[x].append(y)
	graph[y].append(x)

visited =set()
def dfs(src):
	global graph, lazy, visited
	visited.add(src)
	for neighbour in graph[src]:
		if neighbour not in visited:
			lazy[neighbour] += lazy[src]
			dfs(neighbour)

lazy = [0]*(n+1)
queries = [(1, 1), (2, 2)]
for i in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	# idx, val = queries[i]
	lazy[idx] += val
dfs(1)
print(*lazy[1:])

Fixed submission:
import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())

lazy = [0]*(n+1)

graph = defaultdict(lambda:list([]))
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	# x, y = arr[i]
	graph[x].append(y)
	graph[y].append(x)

def dfs(src):
	visited ={src, }
	stack = [src]

	while stack:
		v = stack.pop()
		for next_v in graph[v]:
			if not next_v in visited:
				visited.add(next_v)
				lazy[next_v] += lazy[v]
				stack.append(next_v)

# queries = [(1, 1), (2, 2)]
for i in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	# idx, val = queries[i]
	lazy[idx] += val
dfs(1)
print(*lazy[1:])

Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())

graph = defaultdict(list)
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	graph[x].append(y)
	graph[y].append(x)

def dfs(src, p):
	global graph, lazy

	for neighbour in graph[src]:
		if neighbour != p:
			lazy[neighbour] += lazy[src]
			dfs(neighbour, src)

lazy = [0]*(n+1)
for _ in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	lazy[idx] += val
dfs(1, -1)
print(*lazy[1:])

Fixed submission:
import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())

lazy = [0]*(n+1)

graph = defaultdict(lambda:list([]))
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	# x, y = arr[i]
	graph[x].append(y)
	graph[y].append(x)

def dfs(src):
	visited ={src, }
	stack = [src]

	while stack:
		v = stack.pop()
		for next_v in graph[v]:
			if not next_v in visited:
				visited.add(next_v)
				lazy[next_v] += lazy[v]
				stack.append(next_v)

# queries = [(1, 1), (2, 2)]
for i in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	# idx, val = queries[i]
	lazy[idx] += val
dfs(1)
print(*lazy[1:])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import sys

# n, q = 4, 3
# arr = [(1, 2), (3, 2), (2, 4)]

n , q = map(int, sys.stdin.readline().split())

graph = defaultdict(list)

for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	graph[x].append(y)
	graph[y].append(x)

def dfs(src, p):
	global graph, lazy

	for neighbour in graph[src]:
		if neighbour != p:
			lazy[neighbour] += lazy[src]
			dfs(neighbour, src)


lazy = [0]*(n+1)

for _ in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	lazy[idx] += val
dfs(1, -1)


print(*lazy[1:])



Fixed submission:
import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())

lazy = [0]*(n+1)

graph = defaultdict(lambda:list([]))
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	# x, y = arr[i]
	graph[x].append(y)
	graph[y].append(x)

def dfs(src):
	visited ={src, }
	stack = [src]

	while stack:
		v = stack.pop()
		for next_v in graph[v]:
			if not next_v in visited:
				visited.add(next_v)
				lazy[next_v] += lazy[v]
				stack.append(next_v)

# queries = [(1, 1), (2, 2)]
for i in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	# idx, val = queries[i]
	lazy[idx] += val
dfs(1)
print(*lazy[1:])