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

N,Q=map(int,input().split())

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

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

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,Q,*abpx=map(int,sys.stdin.read().split())

graph=[[] for _ in range(N)]
for a,b in zip(*[iter(abpx[:2*(N-1)])]*2):
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

f=[0]*N
for p,x in zip(*[iter(abpx[2*(N-1):])]*2):
    p-=1
    f[p]+=x

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)

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

N,Q=map(int,input().split())

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

f=defaultdict(int)
for _ in range(Q):
    p,x=map(int,input().split())
    f[p]+=x

visited=[False]*(N+1)
q=deque([])
q.append([1,0])
res=[0 for i in range(N+1)]
while q:
    i,c = q.pop()
    if visited[i]:
        continue
    visited[i]=True
    ch=g[i]
    w=c+f[i]
    res[i]=w
    for u in ch:
        q.appendleft([u,w])

print(*res[1:])

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,Q,*abpx=map(int,sys.stdin.read().split())

graph=[[] for _ in range(N)]
for a,b in zip(*[iter(abpx[:2*(N-1)])]*2):
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

f=[0]*N
for p,x in zip(*[iter(abpx[2*(N-1):])]*2):
    p-=1
    f[p]+=x

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)

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

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

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

used=[False]*N
def solve(x):
    used[x]=True
    for y in graph[x]:
        if used[y]:
            continue
        ans[y]+=ans[x]
        solve(y)

for i in range(N):
    solve(i)

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,Q,*abpx=map(int,sys.stdin.read().split())

graph=[[] for _ in range(N)]
for a,b in zip(*[iter(abpx[:2*(N-1)])]*2):
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

f=[0]*N
for p,x in zip(*[iter(abpx[2*(N-1):])]*2):
    p-=1
    f[p]+=x

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)

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

N,Q=map(int,input().split())

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

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

seen=["False" for _ in range(N)]
def solve(n):
  seen[n]="True"
  for i in graph[n]:
    if seen[i]=="False":
      ans[i]+=ans[n]
      solve(i)
  return

solve(0)
print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,Q,*abpx=map(int,sys.stdin.read().split())

graph=[[] for _ in range(N)]
for a,b in zip(*[iter(abpx[:2*(N-1)])]*2):
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

f=[0]*N
for p,x in zip(*[iter(abpx[2*(N-1):])]*2):
    p-=1
    f[p]+=x

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)

Buggy python submission (verdict: Runtime Error):
mport sys
sys.setrecursionlimit(10**9)

N,Q=map(int,input().split())

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

ans=[0]*N

def px(p,x):
  for i in link[p]:
    ans[i]+=x
    px(i,x)

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

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,Q,*abpx=map(int,sys.stdin.read().split())

graph=[[] for _ in range(N)]
for a,b in zip(*[iter(abpx[:2*(N-1)])]*2):
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

f=[0]*N
for p,x in zip(*[iter(abpx[2*(N-1):])]*2):
    p-=1
    f[p]+=x

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)

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)]

link=[[] for _ in range(N)]
for i in range(N-1):
  a=AB[i][0]-1
  b=AB[i][1]-1
  link[a].append(b)

ans=[0]*N

def px(p,x):
  for i in link[p]:
    ans[i]+=x
    px(i,x)

for i in range(Q):
  p=PX[i][0]-1
  x=PX[i][1]
  ans[p]+=x
  px(p,x)

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,Q,*abpx=map(int,sys.stdin.read().split())

graph=[[] for _ in range(N)]
for a,b in zip(*[iter(abpx[:2*(N-1)])]*2):
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

f=[0]*N
for p,x in zip(*[iter(abpx[2*(N-1):])]*2):
    p-=1
    f[p]+=x

ans=[0 for _ in range(N)]
visited=[False]*N
def c(i,p):
    if visited[i]:
        return 
    visited[i]=True
    w=f[i]+p
    ans[i]=w
    ch=graph[i]
    for x in ch:
        c(x,w)

c(0,0)
print(*ans)