Buggy python submission (verdict: Runtime Error):
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
tree_list = {0: []}
out_put_list = [0] * N

for i in range(N-1):
    tree_list[i+1] = []
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Time Limit Exceeded):

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
candidate_list = []
tree_list = [[]] * N
out_put_list = [0] * N

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_list[a-1] = tree_list[a-1] + [b-1]

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
candidate_list = []
tree_list = [[]] * N
out_put_list = [0] * N
def f(p,x):
    out_put_list[p] += x
    for idx in tree_list[p]:
        f(idx,x)

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_list[a-1] = tree_list[a-1] + [b-1]

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    f(p-1,x)

print(*out_put_list)

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Runtime Error):
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
candidate_list = []
tree_list = [[]] * N
out_put_list = [0] * N
def f(p,x):
    out_put_list[p] += x
    for idx in tree_list[p]:
        f(idx,x)

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_list[a-1] = tree_list[a-1] + [b-1]

print(tree_list)
for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    f(p-1,x)

print(*out_put_list)

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Runtime Error):
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
candidate_list = []
tree_dict = [[]] * N
#Make tree dict
for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    candidate_list.append((a,b))
candidate_list.reverse()
for candidate in candidate_list:
    a = candidate[0]
    b = candidate[1]
    tree_dict[a] += tree_dict[b] + [b]
        
out_put_list = [0] * N
for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x
    for idx in tree_dict[p]:
        out_put_list[idx-1] += x
    
print(' '.join(map(str,out_put_list)))

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Time Limit Exceeded):
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
candidate_list = []
tree_dict = {}
#Make tree dict
for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_dict[i+1] = {
                'count': 0,
                'has_trees': []
            }
    candidate_list.append((a,b))
tree_dict[N] = {
    'count': 0,
    'has_trees': []
    }
candidate_list.reverse()
 
for candidate in candidate_list:
    a = candidate[0]
    b = candidate[1]
    tree_dict[a]['has_trees'] += tree_dict[b]['has_trees'] + [b]
        
 
for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    tree_dict[p]['count'] += x
out_put_list = [0] * N
for k, v  in tree_dict.items():
    out_put_list[k-1] += v['count']
    for idx in v['has_trees']:
        out_put_list[idx-1] += v['count']
print(' '.join(map(str,out_put_list)))

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Time Limit Exceeded):

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
candidate_list = [0] * (N-1)
tree_dict = {}
#Make tree dict
for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_dict[i+1] = {
                'count': 0,
                'has_trees': []
            }
    candidate_list[N-2-i] = (a,b)
tree_dict[N] = {
    'count': 0,
    'has_trees': []
    }
for candidate in candidate_list:
    a = candidate[0]
    b = candidate[1]
    tree_dict[a]['has_trees'] += tree_dict[b]['has_trees'] + [b]
        

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    tree_dict[p]['count'] += x
    for num in tree_dict[p]['has_trees']:
        tree_dict[num]['count'] += x

out_put_list = []
for each_dict in tree_dict.values():
    out_put_list.append(str(each_dict['count']))
print(' '.join(out_put_list))

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Time Limit Exceeded):

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])

tree_dict = {
    N: {
        'count': 0,
        'has_trees': []
    }
}

def f(p,x):
    tree_dict[p]['count'] += x
    for num in tree_dict[p]['has_trees']:
        f(num,x)

candidate_list = []

#Make tree dict
for _ in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    candidate_list.append((a,b))

candidate_list.reverse()

for candidate in candidate_list:

    a = candidate[0]
    b = candidate[1]
    if b not in tree_dict.keys():
        tree_dict[b] = {
                'count': 0,
                'has_trees': []
            }

    if a not in tree_dict.keys():
        tree_dict[a] = {
                'count': 0,
                'has_trees': tree_dict[b]['has_trees'] + [b]
            }
    else:
        tree_dict[a]['has_trees'] += tree_dict[b]['has_trees'] + [b]

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    tree_dict[p]['count'] += x
    for num in tree_dict[p]['has_trees']:
        tree_dict[num]['count'] += x

out_put_list = []
for each_dict in tree_dict.values():
    out_put_list.append(str(each_dict['count']))
print(' '.join(out_put_list))

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(1000000000)
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])

tree_dict = {
    1: {
        'count': 0,
        'has_trees': []
    }
}

def f(p,x):
    tree_dict[p]['count'] += x
    for num in tree_dict[p]['has_trees']:
        f(num,x)


#Make tree dict
for _ in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_dict[a]['has_trees'].append(b)
    if b not in tree_dict.keys():
        tree_dict[b] = {
                'count': 0,
                'has_trees': []
            }

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    f(p,x)

out_put_list = []
for each_dict in tree_dict.values():
    out_put_list.append(str(each_dict['count']))
print(' '.join(out_put_list))

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Buggy python submission (verdict: Runtime Error):

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])

tree_dict = {
    1: {
        'count': 0,
        'has_trees': []
    }
}

def f(p,x):
    tree_dict[p]['count'] += x
    for num in tree_dict[p]['has_trees']:
        f(num,x)


#Make tree dict
for _ in range(N-1):
    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])
    tree_dict[a]['has_trees'].append(b)
    if b not in tree_dict.keys():
        tree_dict[b] = {
                'count': 0,
                'has_trees': []
            }

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    f(p,x)

out_put_list = []
for each_dict in tree_dict.values():
    out_put_list.append(str(each_dict['count']))
print(' '.join(out_put_list))

Fixed submission:

NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = {}
for i in range(N):
    tree_list[i] = []

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)