Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    child = [[] for _ in range(n+1)]
    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        p = que.popleft()
        for l in link[p]:
            if unchecked[l]:
                unchecked[l] = False
                child[p].append(l)
                parent[l] = p
                que.append(l)

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    que = deque([1])
    while que:
        node = que.pop()
        cnt[node] += cnt[parent[node]]
        que.extend(child[node])

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        node = que.pop()
        for l in link[node]:
            if unchecked[l]:
                unchecked[l] = False
                cnt[l] += cnt[node]
                que.append(l)

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    child = [[] for _ in range(n+1)]
    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        p = que.popleft()
        for l in link[p]:
            if unchecked[l]:
                unchecked[l] = False
                child[p].append(l)
                parent[l] = p
                que.append(l)

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    que = deque([1])
    while que:
        node = que.pop()
        cnt[node] += cnt[parent[node]]
        que.extend(child[node])

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        node = que.pop()
        for l in link[node]:
            if unchecked[l]:
                unchecked[l] = False
                cnt[l] += cnt[node]
                que.append(l)

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    child = [[] for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        parent = que.popleft()
        for l in link[parent]:
            if unchecked[l]:
                unchecked[l] = False
                child[parent].append(l)
                que.append(l)

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        p, x = m
        que = deque([p])
        while que:
            node = que.popleft()
            cnt[node] += x
            for c in child[node]:
                que.append(c)

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        node = que.pop()
        for l in link[node]:
            if unchecked[l]:
                unchecked[l] = False
                cnt[l] += cnt[node]
                que.append(l)

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()