Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 21:19:43 2019
ABC138D
@author: maezawa
"""

n, q = list(map(int, input().split()))
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    graph[ai].append(bi)
    graph[bi].append(ai)
    
parent = [[] for _ in range(n+1)]
child = [[] for _ in range(n+1)]
current = 1
while current <= n:
    for j in graph[current]:
        if current in child[j]:
            continue
        child[current].append(j)
    current += 1
#print(child)
parray = [-1]*(n+1)
parray[1] = 0
for i in range(1,n+1):
    for j in child[i]:
        parray[j] = i
#print(parray)
tpoint = [0]*(n+1)
for i in range(q):
    pi, xi = list(map(int, input().split()))
    tpoint[pi] += xi
tpmem = [-1]*(n+1)
tpmem[1] = tpoint[1]
for i in range(1, n+1):
    pi = 0
    j = i
    prej = j
    while True:
        if tpmem[j] != -1:
            pi += tpmem[j]
            tpmem[prej]=tpmem[j]
            break
        pi += tpoint[j]
        if parray[j] == -1:
            break
        prej = j
        j = parray[j]
    print(pi)
    tpmem[i] = pi
    

Fixed submission:
n, q = list(map(int, input().split()))
nodes = [[] for _ in range(n)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    nodes[ai-1].append(bi-1)
    nodes[bi-1].append(ai-1)
    
cnts = [0]*n
for _ in range(q):
    pi, xi = list(map(int, input().split()))
    cnts[pi-1] += xi
    
stack = []
visited = set()
stack.append(0)
while stack:
    current = stack.pop(-1)
    visited.add(current)
    for j in nodes[current]:
        if j in visited:
            continue
        cnts[j] += cnts[current]
        stack.append(j)
        
print(*cnts)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 21:19:43 2019
ABC138D
@author: maezawa
"""

n, q = list(map(int, input().split()))
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    graph[ai].append(bi)
    graph[bi].append(ai)
    
parent = [[] for _ in range(n+1)]
child = [[] for _ in range(n+1)]
current = 1
while current <= n:
    for j in graph[current]:
        if current in child[j]:
            continue
        child[current].append(j)
    current += 1
#print(child)
parray = [-1]*(n+1)
parray[1] = 0
for i in range(1,n+1):
    for j in child[i]:
        parray[j] = i
#print(parray)
tpoint = [0]*(n+1)
for i in range(q):
    pi, xi = list(map(int, input().split()))
    tpoint[pi] += xi
tpmem = [-1]*(n+1)
tpmem[1] = tpoint[1]
for i in range(1, n+1):
    pi = 0
    j = i
    while True:
        if tpmem[j] != -1:
            pi += tpmem[j]
            break
        pi += tpoint[j]
        if parray[j] == -1:
            break
        j = parray[j]
    print(pi)
    tpmem[i] = pi
    

Fixed submission:
n, q = list(map(int, input().split()))
nodes = [[] for _ in range(n)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    nodes[ai-1].append(bi-1)
    nodes[bi-1].append(ai-1)
    
cnts = [0]*n
for _ in range(q):
    pi, xi = list(map(int, input().split()))
    cnts[pi-1] += xi
    
stack = []
visited = set()
stack.append(0)
while stack:
    current = stack.pop(-1)
    visited.add(current)
    for j in nodes[current]:
        if j in visited:
            continue
        cnts[j] += cnts[current]
        stack.append(j)
        
print(*cnts)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 21:19:43 2019
ABC138D
@author: maezawa
"""

n, q = list(map(int, input().split()))
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    graph[ai].append(bi)
    graph[bi].append(ai)
    
parent = [[] for _ in range(n+1)]
child = [[] for _ in range(n+1)]
current = 1
while current <= n:
    for j in graph[current]:
        if current in child[j]:
            continue
        child[current].append(j)
    current += 1
#print(child)
parray = [-1]*(n+1)
parray[1] = 0
for i in range(1,n+1):
    for j in child[i]:
        parray[j] = i
#print(parray)
tpoint = [0]*(n+1)
for i in range(q):
    pi, xi = list(map(int, input().split()))
    tpoint[pi] += xi
tpmem = [-1]*(n+1)
for i in range(1, n+1):
    pi = 0
    j = i
    while True:
        if tpmem[j] != -1:
            pi += tpmem[j]
            break
        pi += tpoint[j]
        if parray[j] == -1:
            break
        j = parray[j]
    print(pi)
    tpmem[i] = pi
    

Fixed submission:
n, q = list(map(int, input().split()))
nodes = [[] for _ in range(n)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    nodes[ai-1].append(bi-1)
    nodes[bi-1].append(ai-1)
    
cnts = [0]*n
for _ in range(q):
    pi, xi = list(map(int, input().split()))
    cnts[pi-1] += xi
    
stack = []
visited = set()
stack.append(0)
while stack:
    current = stack.pop(-1)
    visited.add(current)
    for j in nodes[current]:
        if j in visited:
            continue
        cnts[j] += cnts[current]
        stack.append(j)
        
print(*cnts)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 21:19:43 2019
ABC138D
@author: maezawa
"""

n, q = list(map(int, input().split()))
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    graph[ai].append(bi)
    graph[bi].append(ai)
    
parent = [[] for _ in range(n+1)]
child = [[] for _ in range(n+1)]
current = 1
while current <= n:
    for j in graph[current]:
        if current in child[j]:
            continue
        child[current].append(j)
    current += 1
#print(child)
parray = [-1]*(n+1)
parray[1] = 0
for i in range(1,n+1):
    for j in child[i]:
        parray[j] = i
#print(parray)
tpoint = [0]*(n+1)
for i in range(q):
    pi, xi = list(map(int, input().split()))
    tpoint[pi] += xi
for i in range(1, n+1):
    pi = 0
    j = i
    while True:
        pi += tpoint[j]
        if parray[j] == -1:
            break
        j = parray[j]
    print(pi)
    

Fixed submission:
n, q = list(map(int, input().split()))
nodes = [[] for _ in range(n)]
for _ in range(n-1):
    ai, bi = list(map(int, input().split()))
    nodes[ai-1].append(bi-1)
    nodes[bi-1].append(ai-1)
    
cnts = [0]*n
for _ in range(q):
    pi, xi = list(map(int, input().split()))
    cnts[pi-1] += xi
    
stack = []
visited = set()
stack.append(0)
while stack:
    current = stack.pop(-1)
    visited.add(current)
    for j in nodes[current]:
        if j in visited:
            continue
        cnts[j] += cnts[current]
        stack.append(j)
        
print(*cnts)