Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

def bfs():
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = cnt[n]   
        for node in A[n]:
            if node == par:
                continue
            else:
                cnt[node] += val
                st.append([node,n])
    return cnt

        
N,Q = (int(i) for i in input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

bfs()

print(*cnt)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

def bfs(count,adj):
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = count[n]   
        for node in adj[n]:
            if node == par:
                continue
            else:
                count[node] += val
                st.append([node,n])
    return count

        
N,Q = (int(i) for i in input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

cnt = bfs(cnt,A)

print(*cnt)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

def bfs(count,adj):
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = count[n]   
        for node in adj[n]:
            if node == par:
                continue
            else:
                count[node] += val
                st.append([node,n])
    return count

        
N,Q = map(int, input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

cnt = bfs(cnt,A)

print(*cnt)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(count,adj):
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = count[n]   
        for node in adj[n]:
            if node == par:
                continue
            else:
                count[node] += val
                st.append([node,n])
    return count

        
N,Q = map(int, input().split())
A = [[] for i in range(N)]

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

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

cnt = bfs(cnt,A)

print(*cnt)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(count,adj):
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = count[n]   
        for node in adj[n]:
            if node == par:
                continue
            else:
                count[node] += val
                st.append([node,n])
    return count

        
N,Q = map(int, input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

cnt = bfs(cnt,A)

print(*cnt)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(count,adj):
    check = [0]*N
    st = deque()
    push,pop = st.append, st.pop
    push(0)
    check[0] = 1
    while st:
        n = []
        while st:
            n.append(pop())
        for ni in n:
            for i in adj[ni]:
                #print(ni,i,count)
                if check[i] == 0:
                    count[i] += count[ni]
                    check[i] = 1
                    push(i)
    return count

        
N,Q = map(int, input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

cnt = bfs(cnt,A)

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(count,adj):
    check = [0]*N
    st = deque()
    push,pop = st.append, st.pop
    push(0)
    check[0] = 1
    while st:
        n = []
        while st:
            n.append(pop())
        for ni in n:
            for i in adj[ni]:
                #print(ni,i,count)
                if check[i] == 0:
                    count[i] += count[ni]
                    check[i] = 1
                    push(i)
    return count

        
N,Q = map(int, input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

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

cnt = bfs(cnt,A)

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(count,adj):
    check = [0]*N
    st = deque()
    sts = deque()
    push,pop = st.append, st.pop
    pushs,pops = sts.append, sts.pop
    push(0)
    check[0] = 1
    while st:
        n = []
        while st:
            n.append(pop())
        for ni in n:
            for i in adj[ni]:
                #print(ni,i,count)
                if check[i] == 0:
                    count[i] += count[ni]
                    check[i] = 1
                    pushs(i)
        while sts:
            push(pops())
    return count

        
N,Q = map(int, input().split())
A = [() for i in range(N)]

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

cnt = bfs(cnt,A)

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(count,adj):
    check = [0]*N
    st = deque()
    sts = deque()
    push,pop = st.append, st.pop
    pushs,pops = sts.append, sts.pop
    push(0)
    check[0] = 1
    while st:
        n = []
        while st:
            n.append(pop())
        for ni in n:
            for i in adj[ni]:
                #print(ni,i,count)
                if check[i] == 0:
                    count[i] += count[ni]
                    check[i] = 1
                    pushs(i)
        while sts:
            push(pops())
    return count

        
N,Q = map(int, input().split())
A = [() for i in range(N)]

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

cnt = bfs(cnt,A)

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
chi = [set([i]) for i in range(N)]
par = [set([i]) for i in range(N)]


for n in range(N-1):
    a,b = map(int, input().split())
    chi[a-1].add(b-1)
    par[b-1].add(a-1)
    f = par[a-1]
    for i in f:
        chi[i] = chi[i] | chi[a-1]
        par[a-1] = par[a-1] | par[i]
            
cnt = [0]*N   
for q in range(Q):
   p,x = map(int, input().split())
   for i in chi[p-1]:
       cnt[i] += x

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
chi = [set([i]) for i in range(N)]


for n in range(N-1):
    a,b = map(int, input().split())
    chi[a-1].add(b-1)
    for i in range(N):
        if a-1 in chi[i]:
            chi[i] = chi[i] | chi[a-1]  
            
cnt = [0]*N   
for q in range(Q):
   p,x = map(int, input().split())
   for i in chi[p-1]:
       cnt[i] += x

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,Q = map(int, input().split())
chi = np.zeros((N,N))

for n in range(N-1):
    a,b = map(int, input().split())
    chi[a-1,b-1] = 1
    for i in range(N):
        if chi[i,a-1] > 0:
            chi[i] += chi[a-1] 
            
cnt = [0]*N   
for q in range(Q):
   p,x = map(int, input().split())
   cnt[p-1] += x
   for i in range(N):
       if chi[p-1,i] > 0:
           cnt[i] += x

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,Q = map(int, input().split())
chi = np.zeros((N,N))

for n in range(N-1):
    a,b = map(int, input().split())
    chi[a-1,b-1] = 1
    for i in range(N):
        if chi[i,a-1] > 0:
            chi[i] += chi[a-1] 
            
cnt = [0]*N   
for q in range(Q):
   p,x = map(int, input().split())
   cnt[p-1] += x
   for i in range(N):
       if chi[p-1,i] > 0:
           cnt[i] += x

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
chi = [[0] * (N) for i in range(N)]

for n in range(N-1):
    a,b = map(int, input().split())
    chi[a-1][b-1] = 1
    for i in range(N):
        if chi[i][a-1] == 1:
            for j in range(N):
                chi[i][j] = max(chi[i][j],chi[a-1][j])

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

for n in range(N):
    print(cnt[n], end=" ")

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

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

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

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)