Buggy python submission (verdict: Runtime Error):
from collections import defaultdict


def dfs(u, add):
    cnt[u] += add
    for nu in graph[u]:
        dfs(nu, add)


n, q = map(int, input().split())
graph = defaultdict(list)

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

cnt = [0] * (n + 1)


for _ in range(q):
    p, x = map(int, input().split())
    dfs(p, x)

print(*cnt[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve(graph, arr):
    curr, root = 1, -1
    visited = [True] * 2 + [False] * (n - 1)

    def dfs(curr, root):
        stack = graph[curr]

        while stack:
            leaf = stack.pop()
            if visited[leaf]:
                continue
            arr[leaf] += arr[curr]
            visited[leaf] = True
            dfs(leaf, curr)

        return arr

    return dfs(curr, root)


ans = solve(graph, arr)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve(graph, arr):
    curr, root = 1, -1
    visited = [True] * 2 + [False] * (n - 1)

    def dfs(curr, root):
        stack = graph[curr]

        while stack:
            leaf = stack.pop()
            if visited[leaf]:
                continue
            arr[leaf] += arr[curr]
            visited[leaf] = True
            dfs(leaf, curr)

        return arr

    return dfs(curr, root)


ans = solve(graph, arr)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from collections import deque
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(deque)

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

arr = [0] * (n + 1)

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


def solve(graph, arr):
    curr, root = 1, -1
    visited = [True] * 2 + [False] * (n - 1)

    def dfs(curr, root):
        stack = graph[curr]

        while stack:
            leaf = stack.pop()
            if visited[leaf]:
                continue
            arr[leaf] += arr[curr]
            visited[leaf] = True
            dfs(leaf, curr)

        return arr

    return dfs(curr, root)


ans = solve(graph, arr)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(deque)

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

arr = [0] * (n + 1)

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


visited = [False] * (n + 1)


def dfs(curr):
    stack = graph[curr]

    while stack:
        leaf = stack.pop()
        if visited[leaf]:
            continue
        arr[leaf] += arr[curr]
        visited[leaf] = True
        dfs(leaf)


print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

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

graph = [set() for _ in range(n + 1)]

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve(graph, arr):
    curr, root = 1, -1
    visited = [0] * (n + 1)

    def dfs(curr, root):
        stack = graph[curr]

        while stack:
            leaf = stack.pop()
            if leaf == root:
                continue
            arr[leaf] += arr[curr]
            dfs(leaf, curr)

        return arr

    return dfs(curr, root)


ans = solve(graph, arr)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from collections import deque
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(deque)

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

arr = [0] * (n + 1)

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


def dfs(curr, root):
    stack = graph[curr]

    while stack:
        leaf = stack.pop()
        if leaf == root:
            continue
        arr[leaf] += arr[curr]
        dfs(leaf, curr)


dfs(1, -1)

print(*arr[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from collections import deque
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(deque)

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

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


def solve(graph, arr):
    curr, root = 1, -1

    def dfs(curr, root):
        stack = graph[curr]

        while stack:
            leaf = stack.pop()
            if leaf == root:
                continue
            arr[leaf] += arr[curr]
            dfs(leaf, curr)

        return arr

    return dfs(curr, root)


ans = solve(graph, arr)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from collections import deque
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(deque)

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

ans = [0] * (n + 1)

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


def solve(graph, ans):
    curr, root = 1, -1

    def dfs(curr, root):
        stack = graph[curr]

        while stack:
            leaf = stack.pop()
            if leaf == root:
                continue
            ans[leaf] += ans[curr]
            dfs(leaf, curr)

        return ans

    return dfs(curr, root)


ans = solve(graph, ans)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

ans = [0] * (n + 1)

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


def solve(graph, ans):
    curr, root = 1, -1

    def dfs(curr, root):
        for leaf in graph[curr]:
            if leaf == root:
                continue
            ans[leaf] += ans[curr]
            dfs(leaf, curr)
        return ans

    return dfs(curr, root)


ans = solve(graph, ans)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

ans = [0] * (n + 1)

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


def solve(graph, ans):
    curr, root = 1, -1

    def dfs(curr, root):
        for leaf in graph[curr]:
            if leaf == root:
                continue
            ans[leaf] += ans[curr]
            dfs(leaf, curr)
        return ans

    return dfs(curr, root)


ans = solve(graph, ans)

print(*ans[1:])

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])