Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0]*(n+1))
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=deque([1])
done=[0]*(n+1)
while h:
    a=h.popleft()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

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

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
	a,b=map(int,input().split())
 	g[a].append(b)
 	g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 	v,val=map(int,input().split())
 	cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 	v=q.pop()
 	checked[v]=1 #頂点を見たかどうかのフラグを更新する
 	for u in g[v]:
   		if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     		continue
   		cnt[u]+=cnt[v]
   	q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる


Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
from heapq import heappush, heappop
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0]*(n+1))
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=heappop(h)
    for i in range(len(data[a])):
        if done[data[a][i]]==1:
            continue
        counter[data[a][i]]+=counter[a]
        heappush(h,data[a][i])
    done[a]=1
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
from heapq import heappush, heappop
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0 for i in range(n+1)])
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[]
while h:
    a=heappop(h)
    for i in range(len(data[a])):
        if data[a][i] in done:
            continue
        counter[data[a][i]]+=counter[a]
        heappush(h,data[a][i])
    done.append(a)
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0 for i in range(n+1)])
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=deque([1])
while h:
    a=h.popleft()
    for i in range(len(data[a])):
        counter[data[a][i]]+=counter[a]
        h.append(data[a][i])
        data[data[a][i]].remove(a)
counter.popleft()
print(*counter)


Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0 for i in range(n+1)])
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=deque([1])
while h:
    a=h.popleft()
    for i in range(len(data[a])):
        counter[data[a][i]]+=counter[a]
        h.append(data[a][i])
        data[data[a][i]].remove(a)
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
from heapq import heappush, heappop
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0 for i in range(n+1)])
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
while h:
    a=heappop(h)
    for i in range(len(data[a])):
        counter[data[a][i]]+=counter[a]
        heappush(h,data[a][i])
        data[data[a][i]].remove(a)
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0 for i in range(n+1)])
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=deque([1])
while h:
    a=h.popleft()
    for i in range(len(data[a])):
        counter[data[a][i]]+=counter[a]
        h.append(data[a][i])
        data[data[a][i]].remove(a)
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Runtime Error):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n)]
counter=[0 for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
        data[a].append(b)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
for i in range(1,n):
    if data[i]:
        for j in range(len(data[i])):
            counter[data[i][j]]+=counter[i]
counter=deque(counter)
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy python submission (verdict: Runtime Error):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n)]
counter=[0 for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
        data[a].append(b)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
for i in range(1,n):
    if data[i]:
        for j in range(len(data[i])):
            counter[data[i][j]]+=counter[i]
counter=deque(counter)
counter.popleft()
print(*counter)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])