Buggy python submission (verdict: Time Limit Exceeded):
def get_answer(ki):
    n = ki[0][0]
    q = ki[0][1]
    #n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    #q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    n_data = ki[1:-q]
    #q_data = ki[-q:]
    q_index = [0] * n
    for qq in ki[-q:]:
        q_index[qq[0] - 1] += qq[1]

    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = []
    for i in range(0, n + 1):
        t_index.append([])
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])

    k_stack = [[1, 0]]
    #t_stack = [1]
    #s_stack = [0]
    r_flag = [0] * n
    while len(k_stack) > 0:
        #i = t_stack.pop()
        #s = s_stack.pop()
        k = k_stack.pop()
        i = k[0]
        s = k[1]
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        s += q_index[i - 1]
        score[i - 1] += s
        k_stack += [[t, s] for t in t_index[i]]
        #t_stack += t_index[i]
        #s_stack += [s] * len(t_index[i])

    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    return s_value


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            s = input1.split(" ")
            input_ki.append([int(s[0]), int(s[1])])
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Time Limit Exceeded):
def get_answer(ki):
    n = ki[0][0]
    q = ki[0][1]
    #n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    #q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    n_data = ki[1:-q]
    #q_data = ki[-q:]
    q_index = [0] * n
    for qq in ki[-q:]:
        q_index[qq[0] - 1] += qq[1]

    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = []
    for i in range(0, n + 1):
        t_index.append([])
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])

    t_stack = [1]
    s_stack = [0]
    r_flag = [0] * n
    while len(t_stack) > 0:
        i = t_stack.pop()
        s = s_stack.pop()
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        s += q_index[i - 1]
        score[i - 1] += s
        t_stack += t_index[i]
        s_stack += [s] * len(t_index[i])

    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    return s_value


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            s = input1.split(" ")
            input_ki.append([int(s[0]), int(s[1])])
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Time Limit Exceeded):
def get_answer(ki):
    n = ki[0][0]
    q = ki[0][1]
    #n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    #q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    n_data = ki[1:-q]
    #q_data = ki[-q:]
    q_index = [0] * n
    for qq in ki[-q:]:
        q_index[qq[0] - 1] += qq[1]

    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = {}
    for i in range(1, n + 1):
        t_index[i] = []
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])


    """
    for qq in q_data:
        i = qq[0]
        if i in q_index.keys():
            q_index[i] += qq[1]
        else:
            q_index[i] = qq[1]
    """

    t_stack = [1]
    s_stack = [0]
    r_flag = [0] * n
    while len(t_stack) > 0:
        i = t_stack.pop()
        s = s_stack.pop()
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        s += q_index[i - 1]
        score[i - 1] += s
        t_stack += t_index[i]
        #for si in range(len(t_index[i])):
        #    s_stack.append(s)
        s_stack += [s] * len(t_index[i])

    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    return s_value


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            s = input1.split(" ")
            input_ki.append([int(s[0]), int(s[1])])
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Time Limit Exceeded):
def get_answer(ki):
    n = ki[0][0]
    q = ki[0][1]
    #n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    #q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    n_data = ki[1:-q]
    q_data = ki[-q:]
    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = {}
    for i in range(1, n + 1):
        t_index[i] = []
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])

    q_index = {}
    for qq in q_data:
        i = qq[0]
        if i in q_index.keys():
            q_index[i] += qq[1]
        else:
            q_index[i] = qq[1]

    t_stack = [1]
    s_stack = [0]
    r_flag = [0] * n
    while len(t_stack) > 0:
        i = t_stack.pop()
        s = s_stack.pop()
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        if i in q_index.keys():
            s += q_index[i]
        score[i - 1] += s
        t_stack += t_index[i]
        for si in range(len(t_index[i])):
            s_stack.append(s)

    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    return s_value


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            s = input1.split(" ")
            input_ki.append([int(s[0]), int(s[1])])
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Time Limit Exceeded):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = {}
    for i in range(1, n + 1):
        t_index[i] = []
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])

    q_index = {}
    for qq in q_data:
        i = qq[0]
        if i in q_index.keys():
            q_index[i] += qq[1]
        else:
            q_index[i] = qq[1]

    t_stack = [1]
    s_stack = [0]
    r_flag = [0] * n
    while len(t_stack) > 0:
        i = t_stack.pop()
        s = s_stack.pop()
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        if i in q_index.keys():
            s += q_index[i]
        score[i - 1] += s
        t_stack += t_index[i]
        for si in range(len(t_index[i])):
            s_stack.append(s)

    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    return s_value


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):

def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    score = [0] * n

    nn = len(n_data)
    for n1 in range(0, nn - 1):
        for n2 in range(n1 + 1, nn):
            if n_data[n1][0] > n_data[n2][0]:
                n_data[n1], n_data[n2] = n_data[n2], n_data[n1]

    t_index = {}
    #for i in range(1, n + 1):
    #    t_index[i] = []

    """
    1-2 2-3 2-4 3-5
    1-2-3-5
       -4

    2 1
    3 2

    """
    for n in n_data:
        if n[0] in t_index.keys():
            t_index[n[0]] = [n[1]]
        else:
            t_index[n[0]].append(n[1])
        for k in t_index.keys():
            if n[0] in t_index[k]:
                t_index[k].append(n[1])

    return ""


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)
    t_index = make_index(n, tree)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        #add_score(tree, score, qq, n_data, index)
        s_index = t_index[index - 1]
        for i in s_index:
            score[i] += qq[1]

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    r0 = [0] * n
    for i in range(n):
        r0[i] = i
    index[0] = r0

    for i in range(1, n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)
    t_index = make_index(n, tree)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        #add_score(tree, score, qq, n_data, index)
        s_index = t_index[index - 1]
        for i in s_index:
            score[i] += qq[1]

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    r0 = [0] * n
    for i in range(n):
        r0[i] = i
    index[0] = r0

    for i in range(1, n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    get_answer(input_ki)


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        add_score(tree, score, qq, n_data, index)

    #score = [str(s) for s in score]
    #s = " ".join(score)
    for s in score:
        print(s, end="")
        print(" ", end="")

    return None


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    r0 = [0] * n
    for i in range(n):
        r0[i] = i
    index[0] = r0

    for i in range(1, n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    get_answer(input_ki)


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        add_score(tree, score, qq, n_data, index)

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    r0 = [0] * n
    for i in range(n):
        r0[i] = i
    index[0] = r0

    for i in range(1, n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        add_score(tree, score, qq, n_data, index)

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    r0 = [0] * n
    for i in range(n):
        r0[i] = i
    index[0] = r0

    for i in range(1, n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        add_score(tree, score, qq, n_data, index)

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    for i in range(n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        add_score(tree, score, qq, n_data, index)

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []


    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy python submission (verdict: Runtime Error):
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        score[index - 1] += qq[1]
        add_score(score, qq, n_data, index)

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(score, qq, n_data, index):
    for nn in n_data:
        if nn[0] == index:
            score[nn[1] - 1] += qq[1]
            add_score(score, qq, n_data, nn[1])


if __name__ == "__main__":
    input_ki = []
    while True:
        input1 = input()
        if not input1:
            break;
        input_ki.append(input1)
    print(get_answer(input_ki))


Fixed submission:
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる