defdistance(p1, p2): return ((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2) ** 0.5 defneighbors(pos): global poses, powers result = set() for i inrange(len(poses)): if i == pos: continue if distance(poses[pos], poses[i]) <= powers[pos]: result.add(i) return result
defprocess(pos): global poses, visited visited.add(pos) neighbor_pos = neighbors(pos) #print(neighbor_pos) iflen(neighbor_pos) == 0: return for neighbor in neighbor_pos: if neighbor notin visited: process(neighbor)