Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import sys
sys.setrecursionlimit(10**7)
def main(n,ab,px):
  g=[[]for _ in range(n)]
  for a,b in ab:
    g[a-1].append(b-1)
    g[b-1].append(a-1)
  ans=[0 for _ in range(n)]
  for p,x in px:
    ans[p-1]+=x  
  def dfs(seen,i):
    seen[i]=1
    for li in [li for li in g[i] if seen[li]==0]:
        ans[li]+=ans[i]
        dfs(seen,li)
  seen=[0 for _ in range(n)]
  dfs(seen,0)
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  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)]
  main(n,ab,px)
  

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import sys
sys.setrecursionlimit(10**7)
def main(n,ab,px):
  g=[[]for _ in range(n)]
  for a,b in ab:
    g[a-1].append(b-1)
    g[b-1].append(a-1)
  ans=[0 for _ in range(n)]
  for p,x in px:
    ans[p-1]+=x  
  def dfs(seen,i):
    seen[i]=1
    l=g[i]
    for li in [li for li in l if seen[li]==0]:
        ans[li]+=ans[i]
        dfs(seen,li)
  seen=[0 for _ in range(n)]
  dfs(seen,0)
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  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)]
  main(n,ab,px)
  

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main(n,ab,px):
  import sys
  sys.setrecursionlimit(10**7)
  g=[[]for _ in range(n)]
  for a,b in ab:
    g[a-1].append(b-1)
    g[b-1].append(a-1)
  ans=[0 for _ in range(n)]
  for p,x in px:
    ans[p-1]+=x  
  def dfs(seen,i):
    seen[i]=1
    l=g[i]
    for li in [li for li in l if seen[li]==0]:
      ans[li]+=ans[i]
      dfs(seen,li)
  seen=[0 for _ in range(n)]
  dfs(seen,0)
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  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)]
  main(n,ab,px)
  

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main(n,ab,px):
  import sys
  sys.setrecursionlimit(10**7)

  g=[[]for _ in range(n)]
  for a,b in ab:
    g[a-1].append(b-1)
    g[b-1].append(a-1)
  ans=[0]*n
  for p,x in px:
    ans[p-1]+=x
  
  def dfs(seen,i):
    seen[i]=1
    l=g[i]
    for li in [li for li in l if seen[li]==0]:
      ans[li]+=ans[i]
      dfs(seen,li)
  seen=[0]*n
  dfs(seen,0)
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  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)]
  main(n,ab,px)
  

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main(n,ab,px):
  g=[[]for _ in range(n+1)]
  for a,b in ab:
    g[a].append(b)
    g[b].append(a)
  ans=[0]*n
  for p,x in px:
    ans[p-1]+=x
  
  def dfs(seen,i):
    seen[i-1]=1
    l=g[i]
    for li in [li for li in l if seen[li-1]==0]:
      ans[li-1]+=ans[i-1]
      dfs(seen,li)
  seen=[0]*n
  dfs(seen,1)
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  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)]
  main(n,ab,px)
  

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main(n,ab,px):
  g=[[]for _ in range(n+1)]
  for a,b in ab:
    g[a].append(b)
    g[b].append(a)

  import sys
  sys.setrecursionlimit(10**7)
  
  # 各頂点を根とした部分木に含まれる頂点を列挙
  d={i:[i] for i in range(1,n+1)}
  def dfs(seen,i):
    ret=[i]
    seen[i-1]=1
    l=g[i]
    for li in [li for li in l if seen[li-1]==0]:
      e=dfs(seen,li)
      for ei in e:
        ret.append(ei)
    d[i]=ret
    return ret
  seen=[0]*n
  s=dfs(seen,1)
  #print(d)
  ans=[0]*n
  for p,x in px:
    for di in d[p]:
      ans[di-1]+=x
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  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)]
  main(n,ab,px)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main(n,ab,px):
  g=[[]for _ in range(n+1)]
  for a,b in ab:
    g[a].append(b)
    g[b].append(a)
  # 各頂点を根とした部分木に含まれる頂点を列挙
  d={i:[i] for i in range(1,n+1)}
  def dfs():
    todo=[[1]]
    while len(todo)>0:
      c=todo.pop()
      l=g[c[-1]]
      for li in set(l)-set(c):
        for ci in c:
          d[ci].append(li)
        ct=c.copy()
        ct.append(li)
        todo.append(ct)
  dfs()
  ans=[0]*n
  for p,x in px:
    for di in d[p]:
      ans[di-1]+=x
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  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)]
  main(n,ab,px)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
n,q=map(int,input().split())
graph=[[] for _ in range(n+1)]
ab=[list(map(int,input().split())) for _ in range(n-1)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
px=[list(map(int,input().split())) for _ in range(q)]
seen=[0]*(n+1)
ans=[0]*(n+1)
for p,x in px:
    ans[p]+=x
def dfs(i):
    seen[i]=1
    for li in graph[i]:
        if seen[li]==0:
            ans[li]+=ans[i]
            dfs(li)
dfs(1)
print(' '.join(map(str,ans[1:])))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
graph=[[] for _ in range(n+1)]
ab=[list(map(int,input().split())) for _ in range(n-1)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
px=[list(map(int,input().split())) for _ in range(q)]
ans=[0]*(n+1)
for p,x in px:
    ans[p]+=x
seen=[0]*(n+1)
def dfs(i):
    seen[i]=1
    for li in graph[i]:
        if seen[li]==0:
            ans[li]+=ans[i]
            dfs(li)
dfs(1)
print(' '.join(map(str,ans[1:])))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
graph=[[] for _ in range(n+1)]
ab=[list(map(int,input().split())) for _ in range(n-1)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
px=[list(map(int,input().split())) for _ in range(q)]
ans=[0]*(n+1)
for p,x in px:
    ans[p]+=x
seen=[0]*(n+1)
def dfs(i):
    seen[i]=1
    l=graph[i]
    for li in l:
        if seen[li]==0:
            ans[li]+=ans[i]
            todo.append(li)
    if len(todo)>0:
        dfs(todo.pop())
todo=[1]
dfs(todo.pop())
print(' '.join(map(str,ans[1:])))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()