Buggy python submission (verdict: Runtime Error):
def main()
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
 
 
	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)
 
	X = [0 for i in range(N)]
	for i in range(Q):
    	p, x = map(int, input().split())
    	X[p-1] += x
 
	def dfs(x, p):
    	for j in T[x]:
        	if j == p:
            	continue
        	X[j] += X[x]
        	dfs(j, x)
 
	dfs(0, -1)
 
	for i in range(N):
    	print(X[i], end =" ")
main()

Fixed submission:
N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")

Buggy python submission (verdict: Runtime Error):
def main()
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
 
 
	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)
 
	X = [0 for i in range(N)]
	for i in range(Q):
    	p, x = map(int, input().split())
    	X[p-1] += x
 
	def dfs(x, p):
    	for j in T[x]:
        	if j == p:
            	continue
        	X[j] += X[x]
        	dfs(j, x)
 
	dfs(0, -1)
 
	for i in range(N):
    	print(X[i], end =" ")
main()

Fixed submission:
N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 

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)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

def dfs(x, p):
    for j in T[x]:
        if j == p:
            continue
        X[j] += X[x]
        dfs(j, x)

dfs(0, -1)

for i in range(N):
    print(X[i], end =" ")


Fixed submission:
N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 

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)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]

def dfs(x, p):
    for j in range(len(T[x])):
        if T[x][j] == p:
            continue
        ans[T[x][j]] += ans[x]
        dfs(T[x][j], x)

dfs(0, -1)

for i in range(N):
    print(ans[i], end =" ")


Fixed submission:
N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 

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)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]

def dfs(x, p):
    for j in range(len(T[x])):
        if j == p:
            continue
        ans[T[x][j]] += ans[x]
        dfs(T[x][j])

dfs(0)

for i in range(N):
    print(ans[i], end =" ")


Fixed submission:
N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 

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

F = [0 for i in range(N)]
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)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]

def dfs(x):
    if F[x] == 1:
        return
    F[x] = 1
    for j in range(len(T[x])):
        if F[T[x][j]] == 1:
            continue
        ans[T[x][j]] += ans[x]
        dfs(T[x][j])

dfs(0)

for i in range(N):
    print(ans[i], end =" ")


Fixed submission:
N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")