Problem p02936 (python)

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(2*10**5)
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

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

    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    queue = []

    parent = [1]
    def mktree(v, parent, E):
        children = E[v]
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    while parent:
        p = parent.pop()
        for child in E[p]:
            E[child].remove(p)
            parent.append(child)

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    parent = [1]
    while parent:
        p = parent.pop()
        c = counter[p]
        for child in E[p]:
            counter[child] += c
            parent.append(child)

    print(" ".join(str(x) for x in counter[1:]))

main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

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

    def mktree(v, parent, E):
        children = E[v]
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    for child in E[1]:
        mktree(child, 1, E)

    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    #get(1, E, counter)
    #print(" ".join(str(x) for x in counter[1:]))

main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

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

    def mktree(v, parent, E):
        children = E[v]
        if parent not in children:
            return
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    for child in E[1]:
        mktree(child, 1, E)

    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    get(1, E, counter)
    print(" ".join(str(x) for x in counter[1:]))

main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

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

    def mktree(v, parent, E):
        children = E[v]
        #print(v, ", parent=%d"%parent, E[v])
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    for child in E[1]:
        mktree(child, 1, E)

    if 1==0:
        for child in E[1:]:
            i+=1
            print(i, child)


    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    get(1, E, counter)
    print(" ".join(str(x) for x in counter[1:]))

main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

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

    def mktree(v, parent, E):
        children = E[v]
        #print(v, ", parent=%d"%parent, E[v])
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    for child in E[1]:
        mktree(child, 1, E)

    if 1==0:
        for child in E[1:]:
            i+=1
            print(i, child)


    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    get(1, E, counter)
    print(*[counter[1:]])

main()