Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])

for i in range(210000):
    tree.append(collections.deque([]))
level = collections.deque([-1] * 200100)
parent = collections.deque([-1] * 200100)
cost = collections.deque([0] * 200100)

for loop in range(n - 1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

print(" ".join(list(map(str, cost))[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])
for i in range(210000):
    tree.append(collections.deque([]))
    level.append(-1)
    parent.append(-1)
    cost.append(0)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

res = list(map(str, cost))
print(" ".join(res[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = collections.deque([])
res = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])
cache = collections.deque([])
for i in range(210000):
    res.append(0)
    tree.append(collections.deque([]))
    level.append(-1)
    parent.append(-1)
    cost.append(0)
    cache.append(-1)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        parent[next] = index
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

res = list(map(str, cost))
print(" ".join(res[1:n+1]))


Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = collections.deque([])
res = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])
cache = collections.deque([])
for i in range(210000):
    res.append(0)
    tree.append([])
    level.append(-1)
    parent.append(-1)
    cost.append(0)
    cache.append(-1)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        parent[next] = index
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

res = list(map(str, cost))
print(" ".join(res[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = []
res = []
tree = []
level = []
childs = []
parent = []
cache = []
for i in range(210000):
    res.append(0)
    tree.append([])
    level.append(-1)
    childs.append([])
    parent.append(-1)
    cost.append(0)
    cache.append(-1)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    l = 0
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        #print("index {0} search {1}".format(index, next))
        # 逆走はしない
        if level[next] != -1:
            #print("CANNOT MOVE to {0}".format(next))
            continue
        # 子供に親を設定
        parent[next] = index
        cost[next] += cost[index]
        curparent = index
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

res = list(map(str, cost))
print(" ".join(res[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = []
res = []
tree = []
level = []
childs = []
parent = []
cache = []
for i in range(210000):
    res.append(0)
    tree.append([])
    level.append(-1)
    childs.append([])
    parent.append(-1)
    cost.append(0)
    cache.append(-1)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

def make_level(index, lev, pp):
    l = 0
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        #print("index {0} search {1}".format(index, next))
        # 逆走はしない
        if level[next] != -1:
            #print("CANNOT MOVE to {0}".format(next))
            continue
        # 子供に親を設定
        parent[next] = index
        curparent = index
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

#print("parent")
#print(parent[0:10])

def calc_cost(index):
    if index == -1:
        return 0
    #print("index = {0}, parent = {1}".format(index, parent[index]))
    if cache[parent[index]] != -1:
        #print(" parent has cache: {0}".format(cache[parent[index]]))
        cache[index] = cost[index] + cache[parent[index]]
        #print(" RET index = {0}, COST = {1}".format(index, cost[index] + cache[parent[index]]))
        return cost[index] + cache[parent[index]]
    else:
        cc = calc_cost(parent[index])
        #print(" parent hasNOT cache: {0}".format(cc))
        cache[index] = cost[index] + cc
        #print(" RET index = {0}, COST = {1}".format(index,cost[index] + cc))
        return cost[index] + cc



for i in range(1, n+1):
    #print("llll:{0}".format(i))
    res[i] = calc_cost(i)

res = list(map(str, res))
print(" ".join(res[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
res = []
tree = []
level = []
childs = []
parent = []
for i in range(210000):
    res.append(0)
    tree.append([])
    level.append(-1)
    childs.append([])
    parent.append(-1)


for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

def make_level(index, lev):
    l = 0
    level[index] = lev
    for next in tree[index]:
        # 逆走はしない
        if level[next] != -1:
            continue
        # 子供に親を設定
        parent[next] = index
        curparent = index
        add_parent(index, next)

        make_level(next, lev + 1)


def add_parent(index, childindex):
    if index != -1:
        #print("add {0}, {1}".format(index, childindex))
        childs[index].append((childindex))
        add_parent(parent[index], childindex)


make_level(1, 0)
#print(level[0:10])
#print(parent[0:10])
#print(childs[0:10])

for loop in range(q):
    p, x = map(int, input().split())
    res[p] += x
    for childindex in childs[p]:
        res[childindex] += x

res = list(map(str, res))
print(" ".join(res[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
res = []
tree = []
level = []
for i in range(210000):
    res.append(0)
    tree.append([])
    level.append(-1)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

def make_level(index, lev):
    level[index] = lev
    for next in tree[index]:
        # 逆走はしない
        if level[next] != -1:
            continue
        make_level(next, lev + 1)
make_level(1, 0)
#print(level[0:10])

def do(index, lev, cost):
    res[index] += cost
    for next in tree[index]:
        if level[next] <= lev:
            continue
        do(next, lev + 1, cost)


for loop in range(q):
    p, x = map(int, input().split())
    do(p, level[p], x)

res = list(map(str, res))
print(" ".join(res[1:n+1]))

Fixed submission:
edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))