Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000000)
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]

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

def dfs(u, pre):
  used[u] += 1
  if sum(used) == N:
    return
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u)
  return

dfs(0, -1)
print(*cnt)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000000)
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]


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

def dfs(u, pre, c):
  used[u] += 1
  if sum(used) == N:
    return
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u, cnt[v])

  return

dfs(0, -1, cnt[0])
print(*cnt)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000000)
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]


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

def dfs(u, pre, c):
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u, cnt[v])

dfs(0, -1, cnt[0])
print(*cnt)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000000)
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]


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

def dfs(u, pre, c):
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u, cnt[v])

dfs(0, -1, cnt[0])
print(*cnt)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]


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

def dfs(u, pre, c):
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u, cnt[v])

dfs(0, -1, cnt[0])
print(*cnt)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
px = [list(map(lambda x:int(x)-1, input().split())) for _ in range(Q)]
graph = [[] for _ in range(N)]
for a, b in ab:
  graph[a] += [b]
dist = [0 for _ in range(N)]
for p, x in px:
  dist[p] += x+1

def dfs(u, pre):
  for v in graph[u]:
    if v != pre:
      dist[v] += dist[u]
      dfs(v, u)

  return 

dfs(0, -1)
dist = list(map(str, dist))
print(" ".join(dist))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Runtime Error):
def dfs(v, p, ad_list, count):
  for u in ad_list[v]:
    if u != p:
      count[u] += count[v]
      dfs(u, v, ad_list, count)

def main():
  n, q = map(int, input().split())
  ab = tuple(tuple((map(lambda x: int(x)-1, input().split())) for _ in range(n-1)))
  px = tuple(tuple(map(int, input().split())) for _ in range(q))

  ad_list = [[] for _ in range(n)]
  for a, b in ab:
    ad_list[a] += [b]
    ad_list[b] += [a]

  count = [0 for _ in range(n)]
  for p, x in px:
    count[p-1] += x

  dfs(0, -1, ad_list, count)

  print(*count)

if __name__ == "__main__":
  main()

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
def dfs(v, p, ad_list, count):
  for u in ad_list[v]:
    if u != p:
      count[u] += count[v]
      dfs(u, v, ad_list, count)

def main():
  n, q = map(int, input().split())
  ab = tuple(tuple((map(lambda x: int(x)-1, input().split())) for _ in range(n-1)))
  px = tuple(tuple(map(int, input().split())) for _ in range(q))

  ad_list = [[] for _ in range(n)]
  for a, b in ab:
    ad_list[a] += [b]
    ad_list[b] += [a]

  count = [0 for _ in range(n)]
  for p, x in px:
    count[p-1] += x

  dfs(0, -1, ad_list, count)

  print(*count)

if __name__ == "__main__":
  main()

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
ab = tuple(tuple((map(lambda x: int(x)-1, input().split())) for _ in range(n-1)))
px = tuple(tuple(map(int, input().split())) for _ in range(q))

ad_list = [[] for _ in range(n)]
for a, b in ab:
  ad_list[a] += [b]
  ad_list[b] += [a]

count = [0 for _ in range(n)]
for p, x in px:
  count[p-1] += x


def dfs(v, p, ad_list, count):
  for u in ad_list[v]:
    if u != p:
      count[u] += count[v]
      dfs(u, v, ad_list, count)

dfs(0, -1, ad_list, count)

print(*count)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
n, q = map(int, input().split())
ab = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

ad_list = [deque([]) for _ in range(n)]
for a, b in ab:
  ad_list[a].append(b)

count = [0 for _ in range(n)]

def dfs(v, x, ad):
  count[v] += x
  while ad[v]:
    if len(ad[v]) == 0:
      break
    ad_v = ad[v].pop()
    dfs(ad_v, x, ad)
    
for p, x in px:
  ad = copy.deepcopy(ad_list)
  dfs(p-1, x, ad)

print(*count)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n, q = map(int, input().split())
ab = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

ad_list = [[] for _ in range(n)]
for a, b in ab:
  ad_list[a].append(b)

count = [0 for _ in range(n)]

def dfs(v, x):
  count[v] += x
  ad = copy.deepcopy(ad_list)
  while len(ad[v]) != 0:
    ad_v = ad[v].pop()
    dfs(ad_v, x)
    if len(ad[v]) == 0:
      break

for p, x in px:
  dfs(p-1, x)

print(*count)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
ad_list = [[] for _ in range(n)]
for a, b in ab:
  ad_list[a-1].append(b)
count = [0 for _ in range(n)]

def dfs(v, x):
  count[v] += x
  if len(ad_list[v]) == 0:
    return 0
  else:
    for ad_v in ad_list[v]:
      dfs(ad_v-1, x)
    return 0

for p, x in px:
  dfs(p-1, x)
print(*count)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)