class Solution:
def maximumDetonation(self, bombs: List[List[int]]) -> int:
def distance(a, b):
return pow((a[0] - b[0])**2 + (a[1] - b[1])**2, 0.5)
g = defaultdict(list)
for i, (x1, y1, r1) in enumerate(bombs):
for j, (x2, y2, r2) in enumerate(bombs):
if i == j:continue
dis = distance((x1, y1), (x2, y2))
if dis <= r1:
g[i].append(j)
if dis <= r2:
g[j].append(i)
def dfs(i):
cnt = 1
vis[i] = True
for j in g[i]:
if not vis[j]:
cnt += dfs(j)
return cnt
res = 0
n = len(bombs)
for i in range(n):
vis = [False] * n
res = max(res, dfs(i))
return res
07-22
988
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-22
557
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-13