Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

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

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

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

if __name__ == "__main__":
    main()

Fixed submission:
import sys
def main():
    input = sys.stdin.readline
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

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

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int,input().split()))
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = list(map(int,input().split()))
    edges[a].append(b)
    edges[b].append(a)

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

stack = [(1,0)]
ans = [0]*(N+1)
not_checked = [True]*(N+1)
while stack:
    v,cnt = stack.pop()
    ans[v] = cnt+add[v]
    not_checked[v] = False
    for edge in edges[v]:
        if not_checked[edge]:
            stack.append((edge,ans[v]))

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

Fixed submission:
import sys
def main():
    input = sys.stdin.readline
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

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

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
N,Q = list(map(int,input().split()))

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

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

ans = [0]*(N+1)
checked = [False]*(N+1)

def add(point,num):
    ans[point] += num
    checked[point] = True
    for c in connections[point]:
        if checked[c]:
            continue
        else:
            add(c,num+add_list[c])
            
add(1,add_list[1])

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

Fixed submission:
import sys
def main():
    input = sys.stdin.readline
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

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

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
N,Q = list(map(int,input().split()))

connections = [[] for i in range(N+1)]

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

add_list = [0]*(N+1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    add_list[p] += x

ans = [0]*(N+1)
checked = [False]*(N+1)
def add(point,num):
    ans[point] += num
    checked[point] = True
    for c in connections[point]:
        if checked[c]:
            continue
        else:
            add(c,num+add_list[c])
        
add(1,add_list[1])

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

Fixed submission:
import sys
def main():
    input = sys.stdin.readline
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

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

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

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

if __name__ == "__main__":
    main()