Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] = x

visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for child in edges[parent]:
        if visited[child] == 1:
            continue
        else:
            counter[child] += counter[parent]
            dfs(child)


dfs(0)
print(*counter)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x
visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for c in edges[parent]:
        if visited[c] == 1:
            continue
        else:
            counter[c] += counter[parent]
            dfs(c)


dfs(0)
print(*counter)

Buggy python submission (verdict: Runtime Error):
from collections import deque
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] = x

visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for child in edges[parent]:
        if visited[child] == 1:
            continue
        else:
            counter[child] += counter[parent]
            dfs(child)


dfs(0)
print(*counter)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x
visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for c in edges[parent]:
        if visited[c] == 1:
            continue
        else:
            counter[c] += counter[parent]
            dfs(c)


dfs(0)
print(*counter)

Buggy python submission (verdict: Runtime Error):
from collections import deque
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] = x

visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for child in edges[parent]:
        if visited[child] == 1:
            continue
        else:
            counter[child] += counter[parent]
            dfs(child)

        
dfs(0)
print(counter)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x
visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for c in edges[parent]:
        if visited[c] == 1:
            continue
        else:
            counter[c] += counter[parent]
            dfs(c)


dfs(0)
print(*counter)