Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i == pi:
      continue
    c[i] += c[ci]
    dsf(i, ci)

dsf(0,-1)

print(*c)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i == pi:
      continue
    c[i] += c[ci]
    dsf(i, ci)

dsf(0,-1)

print(*c)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def spread(pi):
  for i in t[pi]:
    c[i] += c[pi]
    spread(i)

spread(0)

print(*c)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def spread(pi):
  for i in range(len(t[pi])):
    c[t[pi][i]] += c[pi]
    spread(t[pi][i])

spread(0)

print(*c)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

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

l=[list() for i in range(n)]
s=[0]*n

def dfs(t,p):
  for c in l[t]:
    if c==p:
      continue
    s[c]+=s[t]
    dfs(c,t)

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

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

dfs(0,n)

print(*s)
print()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

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

l=[list() for i in range(n)]
s=[0]*(n+1)

def dfs(t,p):
  for c in l[t]:
    if c==p:
      continue
    s[c]+=s[t]
    dfs(c,t)

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

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

dfs(0,n)

for i in range(n):
  print(s[i],' ',end="")
print()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

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

l=[list() for i in range(n)]
s=[0]*(n+1)

def dfs(t,p):
  s[t]+=s[p]
  for c in l[t]:
    if c!=p:
      dfs(c,t)

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

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

dfs(0,n)

for i in range(n):
  print(s[i],' ',end="")
print()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2**5)

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

l=[list() for i in range(n)]
s=[0]*(n+1)

def dfs(t,p):
  s[t]+=s[p]
  for c in l[t]:
    if c!=p:
      dfs(c,t)

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

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

dfs(0,n)

for i in range(n):
  print(s[i],' ',end="")
print()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())

l=[list() for i in range(n)]
s=[0]*n
c=[0]*n

def ladd(p,q):
  s[p]=c[p]+q
  for i in l[p]:
    ladd(i,s[p])

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

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

ladd(0,0)

for i in range(n):
  print(s[i],' ',end="")
print()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())

l=[list() for i in range(n)]
s=[0]*n
c=[0]*n

def ladd(p,q):
  s[p]+=q
  for i in l[p]:
    ladd(i,q)

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

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

for i in range(n):
  ladd(i,c[i])

for i in range(n):
  print(s[i],' ',end="")
print()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())

l=[list() for i in range(n)]
c=[0]*n

def ladd(p,q):
  c[p]+=q
  for i in l[p]:
    ladd(i,q)

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

for i in range(q):
  p,q=map(int,input().split())
  ladd(p-1,q)

for i in range(n):
  print(c[i],' ',end="")
print()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())

l=[list() for i in range(n)]
c=[0]*n

def ladd(p,q):
  c[p]+=q
  for i in l[p]:
    ladd(i,q)

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

for i in range(q):
  p,q=map(int,input().split())
  ladd(p-1,q)

print(c)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n,q=map(int,input().split())
t=[[] for _ in range(n)]
c=[0 for _ in range(n)]

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

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

def dsf(ci,pi):
  for i in t[ci]:
    if i != pi:
      c[i] += c[ci]
      dsf(i, ci)

dsf(0,-1)

print(*c)