Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
#graph = [[] for i in range(200010)]
#ans = [0 for i in range(200010)]
graph = [set() for i in range(N)]
ans = [0 for i in range(N)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)


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

    #graph[a].append(b)
    #graph[b].append(a)
    graph[a].add(b)
    graph[b].add(a)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans)

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
#graph = [[] for i in range(200010)]
#ans = [0 for i in range(200010)]
graph = [set() for i in range(N)]
ans = [0 for i in range(N)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)


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

    #graph[a].append(b)
    #graph[b].append(a)
    graph[a].add(b)
    graph[b].add(a)

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

    #ans[p] += x
    ans[p-1] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans)

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
sys.setrecursionlimit(10**7)


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

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.children = set()
    self.counter = 0

  def add_child(self, child):
    self.children.add(child)
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.counter += root.counter
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x

#=====================================
def solve():
  n,q = [int(i) for i in input().split()]
  trees = [Tree() for i in range(n)]

  for _ in range(n-1):
    a,b = [int(i) for i in input().split()]
    trees[a-1].add_child(trees[b-1])
    trees[b-1].add_child(trees[a-1])

  for _ in range(q):
    p,x = [int(i) for i in input().split()]
    trees[p-1].add_count(x)

  trees[0].reconstruct()
  
  print(*[trees[i].counter for i in range(n)])

#=====================================
if __name__ == '__main__':
  solve()

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.root = None
    self.children = set()
    self.counter = 0

  def add_child(self, child):
    self.children.add(child)
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.root = root
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x

  def recalc_count(self):
    if self.root:
      self.counter += self.root.counter
    for child in self.children:
      child.recalc_count()

#=====================================
def solve():
  n,q = [int(i) for i in input().split()]
  trees = [Tree() for i in range(n)]

  for _ in range(n-1):
    a,b = [int(i) for i in input().split()]
    trees[a-1].add_child(trees[b-1])
    trees[b-1].add_child(trees[a-1])

  trees[0].reconstruct()

  for _ in range(q):
    p,x = [int(i) for i in input().split()]
    trees[p-1].add_count(x)

  trees[0].recalc_count()
  
  print(*[trees[i].counter for i in range(n)])

#=====================================
if __name__ == '__main__':
  solve()

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.root = None
    self.children = set()
    self.counter = 0

  def add_child(self, child):
    self.children.add(child)
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.root = root
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x

  def add_root_count(self):
    if self.root:
      self.counter += self.root.counter
    for child in self.children:
      child.add_root_count()

#=====================================
def solve():
  n,q = [int(i) for i in input().split()]
  trees = [Tree() for i in range(n)]

  for _ in range(n-1):
    a,b = [int(i) for i in input().split()]
    trees[a-1].add_child(trees[b-1])
    trees[b-1].add_child(trees[a-1])

  trees[0].reconstruct()

  for _ in range(q):
    p,x = [int(i) for i in input().split()]
    trees[p-1].add_count(x)

  trees[0].add_root_count()
  
  print(*[trees[i].counter for i in range(n)])

#=====================================
if __name__ == '__main__':
  solve()

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.root = None
    self.children = set()
    self.counter = 0

  def add_child(self, child):
    self.children.add(child)
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.root = root
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x

  def get_count(self):
    res = self.counter
    if self.root:
      res += self.root.get_count()
    return res
      
#=====================================

def solve():
  n,q = [int(i) for i in input().split()]
  trees = [Tree() for i in range(n)]

  for _ in range(n-1):
    a,b = [int(i) for i in input().split()]
    trees[a-1].add_child(trees[b-1])
    trees[b-1].add_child(trees[a-1])

  trees[0].reconstruct()

  for _ in range(q):
    p,x = [int(i) for i in input().split()]
    trees[p-1].add_count(x)

  print(*[trees[i].get_count() for i in range(n)])

if __name__ == '__main__':
  solve()

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.root = None
    self.children = []
    self.counter = 0

  def add_child(self, child):
    self.children += [child]
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.root = root
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x

  def get_count(self):
    res = self.counter
    if self.root:
      res += self.root.get_count()
    return res
      
#=====================================

def solve():
  n,q = [int(i) for i in input().split()]
  trees = [Tree() for i in range(n)]

  for _ in range(n-1):
    a,b = [int(i) for i in input().split()]
    trees[a-1].add_child(trees[b-1])
    trees[b-1].add_child(trees[a-1])

  trees[0].reconstruct()

  for _ in range(q):
    p,x = [int(i) for i in input().split()]
    trees[p-1].add_count(x)

  print(*[trees[i].get_count() for i in range(n)])

if __name__ == '__main__':
  solve()

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.children = []
    self.counter = 0

  def add_child(self, child):
    self.children += [child]
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x
    for child in self.children:
      child.add_count(x)

#=====================================
def solve():
  n,q = [int(i) for i in input().split()]
  trees = [Tree() for i in range(n)]

  for _ in range(n-1):
    a,b = [int(i) for i in input().split()]
    trees[a-1].add_child(trees[b-1])
    trees[b-1].add_child(trees[a-1])

  trees[0].reconstruct()

  for _ in range(q):
    p,x = [int(i) for i in input().split()]
    trees[p-1].add_count(x)

  print(*[trees[i].counter for i in range(n)])
  
#=====================================
if __name__ == '__main__':
  solve()

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self):
    self.children = []
    self.counter = 0

  def add_child(self, child):
    self.children += [child]
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x
    for child in self.children:
      child.add_count(x)

#=====================================

n,q = [int(i) for i in input().split()]
trees = [Tree() for i in range(n)]

for _ in range(n-1):
  a,b = [int(i) for i in input().split()]
  trees[a-1].add_child(trees[b-1])
  trees[b-1].add_child(trees[a-1])

trees[0].reconstruct()

for _ in range(q):
  p,x = [int(i) for i in input().split()]
  trees[p-1].add_count(x)

print(*[trees[i].counter for i in range(n)])

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])

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

#=====================================
class Tree():
  def __init__(self, n):
    self.children = []
    self.counter = 0

  def add_child(self, child):
    self.children += [child]
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x
    for child in self.children:
      child.add_count(x)

#=====================================
      
trees = [Tree(i) for i in range(n)]

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

trees[0].reconstruct()

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

print(*[trees[i].counter for i in range(n)])

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])