1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| def find(parents, cur, income, answer):
alloc = income//10
if parents[cur] == cur or alloc == 0:
answer[cur] += income-alloc
return
answer[cur] += income-alloc
find(parents, parents[cur], alloc, answer)
return
def solution(enroll, referral, seller, amount):
N = len(enroll)
answer = [0] * N
name2id = {name:i for i,name in enumerate(enroll)}
parents = [i if referral[i]=='-' else name2id[referral[i]] for i in range(N)]
for i in range(len(seller)):
find(parents, name2id[seller[i]], amount[i]*100, answer)
return answer
|