Buggy python submission (verdict: Runtime Error):
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

def dfs(n, vstd, x):
  C[n] += x
  vstd.append(n)
  for i in D[n]:
    if i in vstd:
      continue
    dfs(i, vstd, C[n])

dfs(0, [0], 0)    
print (" ".join(map(str, C)))

Fixed submission:
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

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

Buggy python submission (verdict: Runtime Error):
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = defaultdict(int)
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] = x

def dfs(n, vstd, x):
  C[n] += x
  vstd.append(n)
  for i in D[n]:
    if i in vstd:
      continue
    dfs(i, vstd, C[n])

dfs(0, [0], 0)    
print (" ".join(map(str, C.values())))

Fixed submission:
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

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

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, Q = map(int, input().split())
C = defaultdict(int)
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  
def AddPX(n, x):
  C[n] += x
  for i in D[n]:
    AddPX(i, x)
  
for i in range(Q):
  p, x = map(int, input().split())
  AddPX(p-1, x)
print (" ".join(map(str, C.values())))

Fixed submission:
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

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

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, Q = map(int, input().split())
C = [0] * (N+1)
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a].add(b)
  
def AddPX(n, x):
  C[n] += x
  for i in D[n]:
    AddPX(i, x)
  
for i in range(Q):
  p, x = map(int, input().split())
  AddPX(p, x)

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

Fixed submission:
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

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

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [''] * (N+1)
C = [0] * (N+1)
for i in range(N-1):
  a, b = map(int, input().split())
  if len(A[a]) == 0:
    A[a] = [b]
  else:
    A[a].append(b)
def AddPX(n, x):
  C[n] += x
  for i in A[n]:
    AddPX(i, x)
  
for i in range(Q):
  p, x = map(int, input().split())
  AddPX(p, x)

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


Fixed submission:
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

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

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [''] * (N+1)
C = [0] * (N+1)
for i in range(N-1):
  a, b = map(int, input().split())
  if len(A[a]) == 0:
    A[a] = [b]
  else:
    A[a].append(b)

def AddPX(n, x):
  C[n] += x
  for i in A[n]:
    AddPX(i, x)
  
for i in range(Q):
  p, x = map(int, input().split())
  AddPX(p, x)
print (" ".join(map(str, C[1:])))

Fixed submission:
from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

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