Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, q = map(int, input().split())
es = [[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
use = [1] * n
cnt = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p - 1] += x


def dfs(v, c):
    k = c + cnt[v]
    cnt[v] = k
    use[v] = 0
    for i in es[v]:
        if use[i]:
            dfs(i, k)


dfs(0, 0)
print(*cnt)


Fixed submission:
#再帰のlimitを解除
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())
#何と繋がっているか（隣接リスト）
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

memo = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x

#深さ優先探索 累積和
def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        #1つ先に情報を流す
        memo[nv] += memo[v]
        #dfsを更新
        dfs(nv, v)

dfs(0, -1)

print(*memo)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = [0]
    looked[0] = 0
    while queue:
        now = queue.pop(0)
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Fixed submission:
#再帰のlimitを解除
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())
#何と繋がっているか（隣接リスト）
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

memo = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x

#深さ優先探索 累積和
def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        #1つ先に情報を流す
        memo[nv] += memo[v]
        #dfsを更新
        dfs(nv, v)

dfs(0, -1)

print(*memo)

Buggy python submission (verdict: Time Limit Exceeded):
#再帰のlimitを解除
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())
#何と繋がっているか（隣接リスト）
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

memo = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x

#深さ優先探索 累積和
def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        #1つ先に情報を流す
        memo[nv] += memo[v]
        #dfsを更新
        dfs(nv, v)

dfs(0, -1)

print(*memo)

Fixed submission:
#再帰のlimitを解除
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())
#何と繋がっているか（隣接リスト）
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

memo = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x

#深さ優先探索 累積和
def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        #1つ先に情報を流す
        memo[nv] += memo[v]
        #dfsを更新
        dfs(nv, v)

dfs(0, -1)

print(*memo)