Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.sstrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
prev=[-1]*n
prev[0]=0
def f(n):
    for i in graph[n]:
        if prev[i]==-1:
            prev[i]=n
            f(i)
f(0)
counter=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
score=[0]*n
score[0]=counter[0]
stack=[0]
while stack!=[]:
    memo=[]
    for i in stack:
        for j in graph[i]:
            if j!=prev[i]:
                score[j]=score[i]+counter[j]
                memo.append(j)
    stack=memo
print(" ".join(score))

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
prev=[-1]*n
prev[0]=0
def f(n):
    for i in graph[n]:
        if prev[i]==-1:
            prev[i]=n
            f(i)
f(0)
counter=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
score=[0]*n
score[0]=counter[0]
stack=[0]
while stack!=[]:
    memo=[]
    for i in stack:
        for j in graph[i]:
            if j!=prev[i]:
                score[j]=score[i]+counter[j]
                memo.append(j)
    stack=memo
for k in score:
    print(k,end=" ")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
def Nodify(n):
    for i in graph[n]:
        if Tree[i]==-1:
            Tree[i]=n
            Nodify(i)
def solve(n):
    for i in graph[n]:
        if i==Tree[n]:
            pass
        else:
            ans[i]=ans[n]+counter[i]
            solve(i)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
Tree=[-1]*n
Nodify(0)
Tree[0]=-1
counter=[0 for _ in range(n)]
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
ans=[-1]*n
ans[0]=counter[0]
solve(0)
for i in ans:
    print(i,end=" ")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
def Nodify(n):
    for i in graph[n]:
        if Tree[i]==-1:
            Tree[i]=n
            Nodify(i)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
Tree=[-1]*n
Nodify(0)
counter=[0 for _ in range(n)]
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
for i in range(n):
    y=i
    ret=counter[y]
    while y!=0:
        ret+=counter[Tree[y]]
        y=Tree[y]
    print(ret, end=" ")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
def Nodify(n):
    for i in graph[n]:
        if Tree[i]==-1:
            Tree[i]=n
            Nodify(i)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
Tree=[-1]*n
Nodify(0)
counter=[0 for _ in range(n)]
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
for i in range(n):
    y=i
    ret=counter[y]
    while y!=0:
        ret+=counter[Tree[y]]
        y=Tree[y]
    print(ret, end=" ")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
def Nodify(n):
    for i in graph[n]:
        if Tree[i]==-1:
            Tree[i]=n
            Nodify(i)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
Tree=[-1]*n
Nodify(0)
counter=[0 for _ in range(n)]
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
for i in range(n):
    y=i
    ret=counter[y]
    while y!=0:
        ret+=counter[Tree[y]]
        y=Tree[y]
    print(ret, end=" ")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])