Buggy python submission (verdict: Runtime Error):
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a-=1
        b-=1
        tree[a].append(b)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        add(p,x,tree,score)
    print(s)

def add(p,x,tree,score):
    score[p] += x
    s=tree[p][:]
    while len(s)>0:
        t = s.pop()
        score[t] += x
        for i in tree[t]:
            s.append(i)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    _map, _int, _input = map, int, input
    n, q = _map(_int, _input().split())
    t = [[] for _ in range(n)]
    r = [0]*n
    for _ in range(n-1):
        a, b = map(lambda x: _int(x)-1, _input().split())
        t[a].append(b)
        t[b].append(a) # leafの順序が保証されないため双方向にリンクを設定
    # root(t[0])からleafまで親ノードのリンクを消しながら辿る
    e = [0]
    eadd = e.append
    while len(e) > 0:
        i = e.pop()
        for j in t[i]:
            t[j].remove(i)
            eadd(j)
    
    query = [0] * n
    for _ in range(q):
        p, x = _map(_int, _input().split())
        query[p-1] += x
    
    for p, x in enumerate(query):
        #p -= 1
        r[p] += x
        s = t[p][:]
        spop = s.pop
        sext = s.extend
        while len(s) > 0:
            i = spop()
            r[i] += x
            sext(t[i])
    print(*r)
        
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    _map, _int, _input = map, int, input
    n, q = _map(_int, _input().split())
    t = [[] for _ in range(n)]
    r = [0]*n
    for _ in range(n-1):
        a, b = map(lambda x: _int(x)-1, _input().split())
        t[a].append(b)
        t[b].append(a) # leafの順序が保証されないため双方向にリンクを設定
    # root(t[0])からleafまで親ノードのリンクを消しながら辿る
    e = [0]
    eadd = e.append
    while len(e) > 0:
        i = e.pop()
        for j in t[i]:
            t[j].remove(i)
            eadd(j)
    
    for _ in range(q):
        p, x = _map(_int, _input().split())
        p -= 1
        r[p] += x
        s = t[p][:]
        spop = s.pop
        sext = s.extend
        while len(s) > 0:
            i = spop()
            r[i] += x
            sext(t[i])
    print(*r)
            
        
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, q = map(int, input().split())
    t = [[] for _ in range(n)]
    r = [0]*n
    for _ in range(n-1):
        a, b = map(lambda x: int(x)-1, input().split())
        t[a].append(b)
        t[b].append(a) # leafの順序が保証されないため双方向にリンクを設定
    # root(t[0])からleafまで親ノードのリンクを消しながら辿る
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in t[i]:
            t[j].remove(i)
            e.append(j)
    #print("tree", t)
    
    for _ in range(q):
        p, x = map(int, input().split())
        p -= 1
        r[p] += x
        s = t[p][:]
        while len(s) > 0:
            #print("next", s)
            #print("end", e)
            i = s.pop()
            r[i] += x
            s.extend(t[i])
        #print(">>", *r)
    print(*r)
            
        
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

if __name__ == "__main__":
    main()