Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
X = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    X[p-1] += x
 
ans = [0] * N
 
def setAnswer(parent, number, value):
    ans[number] = value
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i, value + X[i])
 
setAnswer(0, 0, X[0])
 
print(' '.join(map(str, ans)))

Fixed submission:
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(5 * 10**5)
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))


Fixed submission:
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(5 * 10**5)
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
X = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    X[p-1] += x
 
ans = [0] * N
 
def setAnswer(parent, number, value):
    ans[number] = value
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i, value + X[i])
 
setAnswer(0, 0, X[0])
 
print(' '.join(map(str, ans)))

Fixed submission:
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(5 * 10**5)

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

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

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

ans = [0] * N

def setAnswer(parent, number, value):
    ans[number] = value

    for i in M[number]:
        if i != parent:
            setAnswer(number, i, value + X[i])

setAnswer(0, 0, X[0])

print(' '.join(map(str, ans)))


Fixed submission:
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(5 * 10**5)

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

M = [[0] * N for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1][b-1] = M[b-1][a-1] = 1

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

ans = [0] * N

def setAnswer(parent, number, value):
    ans[number] = value

    for i in range(N):
        if i != parent and M[number][i] == 1:
            setAnswer(number, i, value + X[i])

setAnswer(0, 0, X[0])

print(' '.join(map(str, ans)))


Fixed submission:
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))