LeetCode 1298. PYTHON3 纯模拟
原题链接
困难
作者:
Gyp
,
2020-04-10 00:35:14
,
所有人可见
,
阅读 703
class Solution:
def maxCandies(self, st: List[int], ca: List[int], ks: List[List[int]], ct: List[List[int]], ib: List[int]) -> int:
n = len(st)
cF = collections.defaultdict(int)
q = []
for i in ib:
q.append(i)
cF[i] = 1
ans = 0
while q:
cur = q.pop()
if ca[cur] == 0:
continue
ans += ca[cur]
ca[cur] = 0
for k in ks[cur]:
st[k] = 1
if k in cF and ca[k] != 0:
q.append(k)
for c in ct[cur]:
cF[c] += 1
if st[c] == 1 and ca[c] != 0:
q.append(c)
return ans