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

import networkx as nx

n, q = map(int, input().split())

g = nx.Graph()
for i in range(n - 1):
    g.add_edge(*map(lambda x: int(x) - 1, input().split()))

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

d = deque([0])
b[0] = False

while len(d):
    p = d.popleft()
    for i in g.neighbors(p):
        if b[i]:
            a[i] += a[p]
            b[i] = False
            d.append(i)
print(*a)


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

n, q = map(int, input().split())

graph = [deque([]) for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

a = [0] * -~n
b = [True] * -~n
for i in range(q):
    p, x = map(int, input().split())
    a[p] += x

d = deque([1])
b[1] = False

while len(d):
    p = d.popleft()
    for i in graph[p]:
        if b[i]:
            a[i] += a[p]
            b[i] = False
            d.append(i)
print(*a[1:])

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

import networkx as nx

n, q = map(int, input().split())

g = nx.Graph()
for i in range(n - 1):
    g.add_edge(*map(int, input().split()))
nx.set_node_attributes(g, name="a", values=0)
nx.set_node_attributes(g, name="b", values=True)

for i in range(q):
    p, x = map(int, input().split())
    g.nodes[p]["a"] += x

d = deque([1])
g.nodes[1]["b"] = False
while len(d):
    p = d.popleft()
    for i in g.neighbors(p):
        if g.nodes[i]["b"]:
            g.nodes[i]["a"] += g.nodes[p]["a"]
            g.nodes[i]["b"] = False
            d.append(i)
for i in range(1, n + 1):
    print(g.nodes[i]["a"], end=" ")
print("")


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

n, q = map(int, input().split())

graph = [deque([]) for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

a = [0] * -~n
b = [True] * -~n
for i in range(q):
    p, x = map(int, input().split())
    a[p] += x

d = deque([1])
b[1] = False

while len(d):
    p = d.popleft()
    for i in graph[p]:
        if b[i]:
            a[i] += a[p]
            b[i] = False
            d.append(i)
print(*a[1:])

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

import networkx as nx

n, q = map(int, input().split())

g = nx.Graph()
for i in range(n - 1):
    g.add_edge(*map(int, input().split()))
nx.set_node_attributes(g, name="a", values=0)
nx.set_node_attributes(g, name="b", values=True)

for i in range(q):
    p, x = map(int, input().split())
    g.nodes[p]["a"] += x

d = deque([1])
g.nodes[1]["b"] = False
while len(d):
    p = d.popleft()
    for i in g.neighbors(p):
        if g.nodes[i]["b"]:
            g.nodes[i]["a"] += g.nodes[p]["a"]
            g.nodes[i]["b"] = False
            d.append(i)
for i in range(1, n + 1):
    print(g.nodes[i]["a"], end=" ")
print("")


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

n, q = map(int, input().split())

graph = [deque([]) for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

a = [0] * -~n
b = [True] * -~n
for i in range(q):
    p, x = map(int, input().split())
    a[p] += x

d = deque([1])
b[1] = False

while len(d):
    p = d.popleft()
    for i in graph[p]:
        if b[i]:
            a[i] += a[p]
            b[i] = False
            d.append(i)
print(*a[1:])