Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)
n,q = map(int, input().split())
edge = [[] for _ in range(n)]
counter = [0]*n
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for _ in range(q):
    a, b = map(int, input().split())
    counter[a-1] += b
def dfs(start, prev=-1):
    for i in edge[start]:
        if i == prev: continue
        counter[i] += counter[start]
        dfs(i, start)
dfs(0)
print(*counter)

Fixed submission:
from collections import deque
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
count = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    count[p-1] += x
q = deque([0])
d = [0]*n
while q:
    v = q.popleft()
    d[v] = 1
    for i in g[v]:
        if d[i]:
            continue
        count[i] += count[v]
        q.append(i)
print(*count)

Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
edge = [[] for _ in range(n)]
counter = [0]*n
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for _ in range(q):
    a, b = map(int, input().split())
    counter[a-1] += b
def dfs(start, prev=-1):
    for i in edge[start]:
        if i == prev: continue
        counter[i] += counter[start]
        dfs(i, start)
dfs(0)
print(*counter)

Fixed submission:
from collections import deque
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
count = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    count[p-1] += x
q = deque([0])
d = [0]*n
while q:
    v = q.popleft()
    d[v] = 1
    for i in g[v]:
        if d[i]:
            continue
        count[i] += count[v]
        q.append(i)
print(*count)

Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
edge = [[] for _ in range(n)]
counter = [0]*n
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for _ in range(q):
    a, b = map(int, input().split())
    counter[a-1] += b
def dfs(start, prev):
    for i in edge[start]:
        if i == prev: continue
        counter[i] += counter[start]
        dfs(i, start)
dfs(0, -1)
print(*counter)

Fixed submission:
from collections import deque
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
count = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    count[p-1] += x
q = deque([0])
d = [0]*n
while q:
    v = q.popleft()
    d[v] = 1
    for i in g[v]:
        if d[i]:
            continue
        count[i] += count[v]
        q.append(i)
print(*count)

Buggy python submission (verdict: Runtime Error):
#26　AtCoder Beginner Contest 138 D - Ki
n, q = map(int, input().split())
edge = [[] for _ in range(n)]
counter = [[] for _ in range(n)]
ans_list = [0]*n

def dfs(start, count):
    ans_list[start] += count
    for c in edge[start]:
        dfs(c, count)

for _ in range(n-1):
    u, v = map(int, input().split())
    edge[u-1].append(v-1)
for _ in range(q):
    u, v = map(int, input().split())
    dfs(u-1, v)
print(*ans_list)

Fixed submission:
from collections import deque
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
count = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    count[p-1] += x
q = deque([0])
d = [0]*n
while q:
    v = q.popleft()
    d[v] = 1
    for i in g[v]:
        if d[i]:
            continue
        count[i] += count[v]
        q.append(i)
print(*count)

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())

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

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

def dfs(x, d, s):
    for y in v[x]:
        if d[y]:
            s += f[y]
            ans[y] = s
            d[y] = 0
            dfs(y, d, s)
            s -= f[y]

ans = [0]*n
d = [1]*n
d[0] = 0
ans[0] = f[0]
s = f[0]
dfs(0, d, s)
print(*ans)

Fixed submission:
from collections import deque
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
count = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    count[p-1] += x
q = deque([0])
d = [0]*n
while q:
    v = q.popleft()
    d[v] = 1
    for i in g[v]:
        if d[i]:
            continue
        count[i] += count[v]
        q.append(i)
print(*count)