Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, input().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))



Fixed submission:
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, input().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
visited = [False for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))



Fixed submission:
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

def main():
    sys.setrecursionlimit(10 ** 6)
    n, q = map(int, input().split())
    adj = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    add_node = [0 for i in range(n)]
    for i in range(q):
        p, x = map(int, input().split())
        add_node[p - 1] += x
    counter = [0 for i in range(n)]
    visited = [False for i in range(n)]
    dfs(0, adj, visited, counter, 0, add_node)
    print(" ".join(str(x) for x in counter))

def dfs(i, adj, visited, counter, add, add_node):
    visited[i] = True
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if not visited[j]:
            dfs(j, adj, visited, counter, add, add_node)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

def main():
    sys.setrecursionlimit(10 ** 6)
    n, q = map(int, input().split())
    adj = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    add_node = [0 for i in range(n)]
    for i in range(q):
        p, x = map(int, input().split())
        add_node[p - 1] += x
    counter = [0 for i in range(n)]
    visited = [False for i in range(n)]
    dfs(0, adj, visited, counter, 0, add_node)
    print(" ".join(str(x) for x in counter))

def dfs(i, adj, visited, counter, add, add_node):
    visited[i] = True
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if not visited[j]:
            dfs(j, adj, visited, counter, add, add_node)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    n, q = map(int, input().split())
    adj = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    add_node = [0 for i in range(n)]
    for i in range(q):
        p, x = map(int, input().split())
        add_node[p - 1] += x
    counter = [0 for i in range(n)]
    visited = [False for i in range(n)]
    dfs(0, adj, visited, counter, 0, add_node)
    print(" ".join(str(x) for x in counter))

def dfs(i, adj, visited, counter, add, add_node):
    visited[i] = True
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if not visited[j]:
            dfs(j, adj, visited, counter, add, add_node)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))