Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)

    res=[0]*n

    def solve(p,x):
        que=[p]
        while que:
            p=que.pop()
            res[p]+=x
            for e in edge[p]:
                que.append(e)
        return
    
    px={}
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        px[p]=px.get(p,0)+x

    for p,x in px.items():
        solve(p,x)

    print(*res)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
from collections import deque
def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)
   
    cost=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        cost[p]+=x

    for idx,e in enumerate(cost):
        if e==0:continue
        for f in edge[idx]:
            cost[f]+=e

    print(*cost)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)

    res=[0]*n

    def solve(p,x):
        que=[p]
        while que:
            p=que.pop()
            res[p]+=x
            for e in edge[p]:
                que.append(e)
        return
    
    px={}
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        px[p]=px.get(p,0)+x

    for p,x in px.items():
        solve(p,x)

    print(*res)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
from collections import deque
def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)
   
    cost=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        cost[p]+=x

    for idx,e in enumerate(cost):
        if e==0:continue
        for f in edge[idx]:
            cost[f]+=e

    print(*cost)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline


n,q=map(int,input().split())

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

res=[0]*n

def solve(p,x):
    que=[p]
    while que:
        p=que.pop()
        res[p]+=x
        for e in edge[p]:
            que.append(e)
    return


for i in range(q):
    p,x=map(int,input().split())
    p-=1
    solve(p,x)

print(*res)

Fixed submission:
import sys
from collections import deque
def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)
   
    cost=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        cost[p]+=x

    for idx,e in enumerate(cost):
        if e==0:continue
        for f in edge[idx]:
            cost[f]+=e

    print(*cost)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline


n,q=map(int,input().split())

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

res=[0]*n

def solve(p,x):
    que=[p]
    while que:
        p=que.pop()
        res[p]+=x
        for e in edge[p]:
            que.append(e)
    return


for i in range(q):
    p,x=map(int,input().split())
    p-=1
    solve(p,x)

print(*res)

Fixed submission:
import sys
from collections import deque
def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)
   
    cost=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        cost[p]+=x

    for idx,e in enumerate(cost):
        if e==0:continue
        for f in edge[idx]:
            cost[f]+=e

    print(*cost)

if __name__ == "__main__":
    main()