Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n-1)]
l.sort()
# print(l)

lq = [list(map(int, input().split())) for _ in range(q)]
lq.sort()
lq_new = []
for i in range(q):
    if i == 0:
        lq_new = [lq[0]]
    else:
        if lq[i][0] == lq[i-1][0]:
            lq_new[-1][1] += lq[i][1]
        else:
            lq_new.append(lq[i])
lq = lq_new

ch = [[] for _ in range(n)]
ad = [[] for _ in range(n)]

for i in range(n-1):
    a, b = l[i][0]-1, l[i][1]-1
    ch[a].append(b)
    ad[b].append(a)
    for x in ad[a]:
        ch[x].append(b)
        ad[b].append(x)

# print(ch)
# print(ad)

ans = [0 for _ in range(n)]
for i in range(len(lq)):
    p, x = lq[i][0]-1, lq[i][1]
    ans[p] += x
    for j in ch[p]:
        ans[j] += x

ans = map(str, ans)
print(" ".join(ans))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n-1)]
l.sort()
# print(l)

lq = [list(map(int, input().split())) for _ in range(q)]

ch = [[] for _ in range(n)]
ad = [[] for _ in range(n)]

for i in range(n-1):
    a, b = l[i][0]-1, l[i][1]-1
    ch[a].append(b)
    ad[b].append(a)
    for x in ad[a]:
        ch[x].append(b)
        ad[b].append(x)

# print(ch)
# print(ad)

ans = [0 for _ in range(n)]
for i in range(q):
    p, x = lq[i][0]-1, lq[i][1]
    ans[p] += x
    for j in ch[p]:
        ans[j] += x

ans = map(str, ans)
print(" ".join(ans))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n-1)]
l.sort()
# print(l)

lq = [list(map(int, input().split())) for _ in range(q)]

ch = [[] for _ in range(n)]
ad = [[] for _ in range(n)]

for i in range(n-1):
    a, b = l[i][0]-1, l[i][1]-1
    ch[a].append(b)
    ad[b].append(a)
    for x in ad[a]:
        ch[x].append(b)
        ad[b].append(x)

# print(ch)
# print(ad)

ans = [0 for _ in range(n)]
for i in range(q):
    p, x = lq[i][0]-1, lq[i][1]
    ans[p] += x
    for j in ch[p]:
        ans[j] += x

ans = map(str, ans)
print(" ".join(ans))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

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

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

ans = [0 for _ in range(n)]
def f(r, y):
    for j in root[r]:
        ans[j] += y
        # print(ans)
        s = j
        f(s, y)

for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
    # print(ans)
    f(p-1, x)

ans = map(str, ans)
print(" ".join(ans))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)