CodeEff/ECCO huggingface dataset:
# Original solution
from pprint import pprint
import queue


def solve(n, q, a, b, p, x):
    counter = [0] * n
    q_sum = [0] * n
    for i in range(q):
        q_sum[p[i]] += x[i]
    # pprint(q_sum)

    edges = {}
    for i in range(n-1):
        if a[i] not in edges:
            edges[a[i]] = []
        edges[a[i]].append(b[i])
    # pprint(edges)

    counter[0] = q_sum[0]
    children = queue.Queue()
    for child in edges[0]:
        counter[child] = q_sum[0]
        children.put(child)
    while not children.empty():
        child = children.get()
        counter[child] += q_sum[child]
        # print("child")
        # print(child, counter[child])
        if child in edges:
            for c in edges[child]:
                counter[c] = counter[child]
                # print("c")
                # print(c, counter[c])
                children.put(c)

    print((" ".join(list(map(str, counter)))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    a = []
    b = []
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        a.append(a_i - 1)
        b.append(b_i - 1)

    p = []
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p.append(p_i-1)
        x.append(x_i)
    solve(n, q, a, b, p, x)

# Optimized solution
from collections import deque


def solve(n, q, a, b, p, x):
    counter = [0] * n
    q_sum = [0] * n
    for i in range(q):
        q_sum[p[i]] += x[i]
    # pprint(q_sum)

    edges = {}
    for i in range(n-1):
        if a[i] not in edges:
            edges[a[i]] = []
        edges[a[i]].append(b[i])
    # pprint(edges)

    counter[0] = q_sum[0]
    children = deque()
    for child in edges[0]:
        counter[child] = q_sum[0]
        children.append(child)
    while children:
        child = children.popleft()
        counter[child] += q_sum[child]
        # print("child")
        # print(child, counter[child])
        if child in edges:
            for c in edges[child]:
                counter[c] = counter[child]
                # print("c")
                # print(c, counter[c])
                children.append(c)

    print((" ".join(list(map(str, counter)))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    a = []
    b = []
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        a.append(a_i - 1)
        b.append(b_i - 1)

    p = []
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p.append(p_i-1)
        x.append(x_i)
    solve(n, q, a, b, p, x)
# Original solution
from pprint import pprint
from collections import deque, defaultdict


def solve(n, q, edges, p):
    counter = defaultdict(int)

    parents = deque()
    parents.append(0)
    while parents:
        parent = parents.popleft()
        counter[parent] += p[parent]
        # print("parent")
        # print(parent, counter[parent])
        if parent in edges:
            for child in edges[parent]:
                counter[child] = counter[parent]
                # print("child")
                # print(child, counter[child])
                parents.append(child)

    print((" ".join(list(map(str, list(counter.values()))))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    edges = defaultdict(list)
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        edges[a_i-1].append(b_i-1)

    p = [0] * n
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p[p_i-1] += x_i

    solve(n, q, edges, p)

# Optimized solution
from pprint import pprint
from collections import deque, defaultdict


def solve(n, q, edges, p):
    counter = defaultdict(int)

    parents = deque()
    parents.append(0)
    while parents:
        parent = parents.popleft()
        counter[parent] += p[parent]
        # print("parent")
        # print(parent, counter[parent])
        if parent in edges:
            for child in edges[parent]:
                if counter[child] != 0:
                    continue
                counter[child] = counter[parent]
                # print("child")
                # print(child, counter[child])
                parents.append(child)

    print((" ".join(list(map(str, list(counter.values()))))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    edges = defaultdict(list)
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        edges[a_i-1].append(b_i-1)

    p = [0] * n
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p[p_i-1] += x_i

    solve(n, q, edges, p)
# Original solution
from pprint import pprint
from collections import deque, defaultdict

n, q = list(map(int, input().strip().split(" ")))
edges = defaultdict(set)
for _ in range(n-1):
    a_i, b_i = list(map(int, input().strip().split(" ")))
    # edges[a_i-1].append(b_i-1)
    # edges[b_i-1].append(a_i-1)
    edges[a_i-1].add(b_i-1)
    edges[b_i-1].add(a_i-1)

# p = defaultdict(int)
# counter = defaultdict(int)
counter = [0] * n
p = [0] * n
x = []
for _ in range(q):
    p_i, x_i = list(map(int, input().strip().split(" ")))
    # p[p_i-1] += x_i
    counter[p_i-1] += x_i


parents = deque()
# parents.append(0)
# parents = []
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    # parent = parents.pop()
    if parent in visited:
        continue
    visited.add(parent)
    # counter[parent] += p[parent]
    # print("parent")
    # print(parent, counter[parent])
    for child in edges[parent]:
        if child in visited:
            continue
        # if counter[child] != 0:
        #    continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)
        # parents.add(child)

#print(" ".join(list(map(str, counter.values()))))
print((" ".join(list(map(str, counter)))))

# Optimized solution
from pprint import pprint
from collections import deque, defaultdict

n, q = list(map(int, input().strip().split(" ")))
# edges = defaultdict(set)
edges = [[] for _ in range(n)]
for _ in range(n-1):
    a_i, b_i = list(map(int, input().strip().split(" ")))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)
    # edges[a_i-1].add(b_i-1)
    # edges[b_i-1].add(a_i-1)

# p = defaultdict(int)
# counter = defaultdict(int)
counter = [0] * n
p = [0] * n
x = []
for _ in range(q):
    p_i, x_i = list(map(int, input().strip().split(" ")))
    # p[p_i-1] += x_i
    counter[p_i-1] += x_i


parents = deque()
# parents.append(0)
# parents = []
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    # parent = parents.pop()
    if parent in visited:
        continue
    visited.add(parent)
    # counter[parent] += p[parent]
    # print("parent")
    # print(parent, counter[parent])
    for child in edges[parent]:
        if child in visited:
            continue
        # if counter[child] != 0:
        #    continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)
        # parents.add(child)

#print(" ".join(list(map(str, counter.values()))))
print((" ".join(list(map(str, counter)))))
# Original solution
from pprint import pprint
from collections import deque, defaultdict

n, q = list(map(int, input().strip().split(" ")))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    a_i, b_i = list(map(int, input().strip().split(" ")))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)

counter = [0] * n
p = [0] * n
for _ in range(q):
    p_i, x_i = list(map(int, input().strip().split(" ")))
    counter[p_i-1] += x_i


parents = deque()
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    if parent in visited:
        continue
    visited.add(parent)
    for child in edges[parent]:
        if child in visited:
            continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)

print((" ".join(list(map(str, counter)))))

# Optimized solution
from pprint import pprint
from collections import deque, defaultdict

import sys

# n, q = map(int, input().strip().split(" "))
n, q = list(map(int, sys.stdin.readline().strip().split(" ")))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    # a_i, b_i = map(int, input().strip().split(" "))
    a_i, b_i = list(map(int, sys.stdin.readline().strip().split(" ")))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)

counter = [0] * n
p = [0] * n
for _ in range(q):
    # p_i, x_i = map(int, input().strip().split(" "))
    p_i, x_i = list(map(int, sys.stdin.readline().strip().split(" ")))
    counter[p_i-1] += x_i


parents = deque()
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    if parent in visited:
        continue
    visited.add(parent)
    for child in edges[parent]:
        if child in visited:
            continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)

print((" ".join(list(map(str, counter)))))
# Original solution
from pprint import pprint
from collections import deque, defaultdict
 
import sys
 
# n, q = map(int, input().strip().split(" "))
n, q = list(map(int, sys.stdin.readline().strip().split(" ")))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    # a_i, b_i = map(int, input().strip().split(" "))
    a_i, b_i = list(map(int, sys.stdin.readline().strip().split(" ")))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)
 
counter = [0] * n
p = [0] * n
for _ in range(q):
    # p_i, x_i = map(int, input().strip().split(" "))
    p_i, x_i = list(map(int, sys.stdin.readline().strip().split(" ")))
    p[p_i-1] += x_i
    # counter[p_i-1] += x_i
 
 
parents = deque()
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    if parent in visited:
        continue
    counter[parent] += p[parent]
    visited.add(parent)
    for child in edges[parent]:
        if child in visited:
            continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)
 
print((" ".join(list(map(str, counter)))))

# Optimized solution
import sys
from collections import deque

N, Q = list(map(int, sys.stdin.readline().split(" ")))

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, sys.stdin.readline().split(" ")))
    # print(a, b)
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
# print(edges)
# sys.exit()

points = [0] * N
for _ in range(Q):
    p, x = list(map(int, sys.stdin.readline().split(" ")))
    points[p-1] += x


visited = set()
counted = [0] * N
q = deque([(0, points[0])])
while q:
    node, point = q.popleft()
    # print(node, point)
    if node in visited:
        continue
    counted[node] = str(point)
    visited.add(node)
    for edge in edges[node]:
        q.appendleft((edge, point + points[edge]))

print((" ".join(counted)))
# Original solution
import queue

N, Q = list(map(int, input().split()))
tree = [[] for _ in range(N+1)]
value = [0] * (N+1)
visit = [False] * (N+1)

# make_tree
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    tree[a].append(b)
    tree[b].append(a)

# make_value
for _ in range(Q):
    p, x = list(map(int, input().split()))
    value[p] += x

# all_value_sum
q = queue.Queue()
q.put(1)
visit[1] = True
while not q.empty():
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            value[next] += value[now]
            q.put(next)
            visit[next] = True

# output_value
s = " ".join(map(str, value[1:]))
print(s)

# Optimized solution
import sys
import queue
input = sys.stdin.readline

N, Q = list(map(int, input().split()))
tree = [[] for _ in range(N+1)]
value = [0] * (N+1)
visit = [False] * (N+1)

# make_tree
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    tree[a].append(b)
    tree[b].append(a)

# make_value
for _ in range(Q):
    p, x = list(map(int, input().split()))
    value[p] += x

# all_value_sum
q = queue.Queue()
q.put(1)
visit[1] = True
while not q.empty():
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            value[next] += value[now]
            q.put(next)
            visit[next] = True

# output_value
s = " ".join(map(str, value[1:]))
print(s)
# Original solution
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, q = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

cost = [0] * n

for i in range(q):
    p, x = [int(item) for item in input().split()]
    p -= 1
    cost[p] += x

ans = [-1] * n
ans.append(0)

def dfs(frm, n):
    if ans[n] != -1:
        return
    ans[n] = ans[frm] + cost[n]
    for to in edge[n]:
        dfs(n, to)

dfs(-1, 0)
print((" ".join([str(item) for item in ans[:-1]])))

# Optimized solution
import sys
sys.setrecursionlimit(10**6)
 
n, q = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)
 
cost = [0] * n
 
for i in range(q):
    p, x = [int(item) for item in input().split()]
    p -= 1
    cost[p] += x
 
ans = [-1] * n
ans.append(0)
 
def dfs(frm, n):
    ans[n] = ans[frm] + cost[n]
    for to in edge[n]:
        if ans[to] != -1:
            continue
        dfs(n, to)
 
dfs(-1, 0)
print((" ".join([str(item) for item in ans[:-1]])))
# Original solution
import sys
sys.setrecursionlimit(1000000)


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

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

parent = [0] * n
res = [0] * n
visited = [False] * n
def dfs(x, n):
    res[x] += n
    visited[x] = True
    for ne in adj[x]:
        if not visited[ne]:
            dfs(ne, n + p[ne])

dfs(0, p[0])
print((' '.join([str(x) for x in res])))



# Optimized solution
import sys

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

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

parent = [0] * n
stack = [0]
while len(stack) > 0:
    i = stack.pop()
    for j in adj[i]:
        res[j] += res[i]
        stack.append(j)

print((' '.join([str(x) for x in res])))
# Original solution
import sys
import collections
sys.setrecursionlimit(1000000)
n, q = list(map(int, input().split()))
cost = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])

for i in range(210000):
    tree.append(collections.deque([]))
level = collections.deque([-1] * 200100)
parent = collections.deque([-1] * 200100)
cost = collections.deque([0] * 200100)

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

for loop in range(q):
    p, x = list(map(int, input().split()))
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

print((" ".join(list(map(str, cost))[1:n+1])))

# Optimized solution
edge = []
n, q = list(map(int, input().split()))
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = list(map(int, input().split()))
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = list(map(int, input().split()))
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print((" ".join(list(map(str, res)))))
# Original solution
N, Q = map(int, input().split())
T = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)

Point = [0] * N
for q in range(Q):
    p, x = map(int, input().split())
    p -= 1
    Point[p] += x

ans = [0] * N

stack = [[0, Point[0]]]
visited = [False] * N
while stack:
    n, p = stack.pop()
    visited[n] = True
    ans[n] = p
    for to in T[n]:
        if visited[to]:
            continue
        stack.append([to, p + Point[to]])

print(*ans, sep=' ')


# Optimized solution
N, Q = map(int, input().split())
T = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)


ans = [None] * N
V = [0] * N
for q in range(Q):
    p, x = map(int, input().split())
    p -= 1
    V[p] += x


stack = [[0, V[0]]]
while stack:
    n, v = stack.pop()
    ans[n] = v

    for to in T[n]:
        if ans[to] is not None:
            continue

        stack.append([to, v + V[to]])


print(*ans, sep=' ')
# Original solution
import sys
input = sys.stdin.readline

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

root = {}
for i in range(n-1):
    a, b = list(map(int, input().split()))
    if a in root:
        root[a] += [b]
    else:
        root.setdefault(a, [b])
    if b in root:
        root[b] += [a]
    else:
        root.setdefault(b, [a])
    
cnt = [0 for _ in range(n+1)]
for i in range(q):
    p, x = list(map(int, input().split()))
    cnt[p] += x

quu = [1]
visited = []
while len(quu) > 0:
    now = quu.pop(0)
    visited += [now]
    child = root[now]
    for i in range(len(child)):
        if not child[i] in visited:
            quu += [child[i]]
            cnt[child[i]] += cnt[now]

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

# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(300000)

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

root = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = list(map(int, input().split()))
    root[a].append(b)
    root[b].append(a)
    
cnt = [0 for _ in range(n+1)]
for i in range(q):
    p, x = list(map(int, input().split()))
    cnt[p] += x

def rec(node, parent):
    for i in root[node]:
        if i == parent:
            continue
        cnt[i] += cnt[node]
        rec(i, node)

rec(1, 1)
print((" ".join(map(str, cnt[1:]))))
# Original solution
import sys
from collections import deque
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def bfs():
    visited[0] = True
    ans[0] = counter[0]
    deq = deque()
    deq.append(0)
    while deq:
        v = deq.popleft()
        for nv in edge[v]:
            if visited[nv] is True:
                continue
            visited[nv] = True
            ans[nv] = ans[v] + counter[nv]
            deq.append(nv)


N, Q = inpl()

edge = [[] for i in range(N)]
for i in range(N - 1):
    a, b = inpl()
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

counter = {k: 0 for k in range(N)}
for i in range(Q):
    p, q = inpl()
    counter[p - 1] = counter.get(p - 1, 0) + q

ans = [0 for i in range(N)]
visited = [False for i in range(N)]

bfs()

print((" ".join(list(map(str, ans)))))


# Optimized solution
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def bfs():
    visited[0] = True
    ans[0] = counter[0]
    deq = deque()
    deq.append(0)
    while deq:
        v = deq.popleft()
        for nv in edge[v]:
            if visited[nv] is True:
                continue
            visited[nv] = True
            ans[nv] = ans[v] + counter[nv]
            deq.append(nv)


N, Q = inpl()

edge = [[] for i in range(N)]
for i in range(N - 1):
    a, b = inpl()
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

counter = {k: 0 for k in range(N)}
for i in range(Q):
    p, q = inpl()
    counter[p - 1] = counter.get(p - 1, 0) + q

ans = [0] * N
visited = [False] * N

bfs()

print((" ".join(list(map(str, ans)))))
# Original solution
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().split()]

edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

cost = [0] * N
for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    cost[p - 1] += x

next = [0]
for i in next:
    for v in edge[i]:
        s_next = set(next)
        if v in s_next:
            continue
        next.append(v)
        cost[v] += cost[i]

print((" ".join(map(str, cost))))





# Optimized solution
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().split()]

edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

cost = [0] * N
for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    cost[p - 1] += x

next = [0]
s_next = {0}
for i in next:
    for v in edge[i]:
        if v in s_next:
            continue
        s_next.add(v)
        next.append(v)
        cost[v] += cost[i]

print((" ".join(map(str, cost))))
# Original solution
N, Q = list(map(int, input().split()))
order_dict = {}
reversed_dict = {}
Q_dict = {}
have_relationlist = {}
ans = []
for i in range(N):
    if i != 0:
        a, b = list(map(int, input().split()))
        if not a in order_dict:
            order_dict[a] = set()
        if not b in reversed_dict:
            reversed_dict[b] = set()
        order_dict[a].add(b)
        reversed_dict[b].add(a)
    ans.append(0)
    have_relationlist[i+1] = set()
    have_relationlist[i+1].add(i+1)

for b in reversed(list(range(2, N+1))):
    for a in reversed_dict[b]:
        if a in order_dict:
            have_relationlist[a] |= order_dict[a]
        have_relationlist[a] |= have_relationlist[b]

for i in range(Q):
    p, x = list(map(int, input().split()))
    for a in have_relationlist[p]:
        ans[a-1] += x

print((' '.join(map(str, ans))))

# Optimized solution
N, Q = list(map(int, input().split()))
order_dict = {}
ans = [0]*N

for i in range(N):
    if i != 0:
        a, b = list(map(int, input().split()))
        if not a in order_dict:
            order_dict[a] = set()
        order_dict[a].add(b)
    

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

for a in range(N+1):
    if a in order_dict:
        for b in order_dict[a]:
            ans[b-1] += ans[a-1]


print((' '.join(map(str, ans))))