You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.

The bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [xi, yi, ri]. xi and yi denote the X-coordinate and Y-coordinate of the location of the ith bomb, whereas ri denotes the radius of its range.

You may choose to detonate a single bomb. When a bomb is detonated, it will detonate all bombs that lie in its range. These bombs will further detonate the bombs that lie in their ranges.

Given the list of bombs, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb.

&nbsp;
Example 1:

Input: bombs = [[2,1,3],[6,1,4]]
Output: 2
Explanation:
The above figure shows the positions and ranges of the 2 bombs.
If we detonate the left bomb, the right bomb will not be affected.
But if we detonate the right bomb, both bombs will be detonated.
So the maximum bombs that can be detonated is max(1, 2) = 2.


Example 2:

Input: bombs = [[1,1,5],[10,10,5]]
Output: 1
Explanation:
Detonating either bomb will not detonate the other bomb, so the maximum number of bombs that can be detonated is 1.


Example 3:

Input: bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]
Output: 5
Explanation:
The best bomb to detonate is bomb 0 because:
- Bomb 0 detonates bombs 1 and 2. The red circle denotes the range of bomb 0.
- Bomb 2 detonates bomb 3. The blue circle denotes the range of bomb 2.
- Bomb 3 detonates bomb 4. The green circle denotes the range of bomb 3.
Thus all 5 bombs are detonated.


&nbsp;
Constraints:


	1 &lt;= bombs.length&nbsp;&lt;= 100
	bombs[i].length == 3
	1 &lt;= xi, yi, ri &lt;= 105


class Solution(object):
    def maximumDetonation(self, bombs):
        def count(i):
            dq, ret = [i], [i]
            while len(dq) > 0:
                i = dq.pop()
                for j in adj[i]:
                    if j not in ret and j not in dq:
                        dq.append(j)
                        ret.append(j)
            return len(ret)

        adj = collections.defaultdict(list)
        for i in range(len(bombs)):
            for j in range(i + 1, len(bombs)):
                if (bombs[i][0] - bombs[j][0]) ** 2 + (bombs[i][1] - bombs[j][1]) ** 2 <= bombs[i][2] ** 2:
                    adj[i].append(j)
                if (bombs[i][0] - bombs[j][0]) ** 2 + (bombs[i][1] - bombs[j][1]) ** 2 <= bombs[j][2] ** 2:
                    adj[j].append(i)
        ret = 0
        for i in range(len(bombs)):
            ret = max(ret, count(i))
        return ret
class Solution {
    /*
    Make directed graph
    u -> v means, v is in the range of u
    check from which node maximum nodes can be reached and return the number of nodes reached
    */
    public int maximumDetonation(int[][] bombs) {
        Map<Integer, List<Integer>> graph = new HashMap<>();

        int n = bombs.length;
        for(int i = 0; i< n; i++){
            graph.put(i, new ArrayList<>());
            for(int j = 0; j< n; j++){
                if(i == j) continue;
                if(inRange(bombs[i], bombs[j]))
                    graph.get(i).add(j);
            }
        }

        int max = 0;
        for(int i = 0; i< n; i++){
            max = Math.max(max, dfs(i, graph, new HashSet<>()));
        }
        return max;
    }

    private boolean inRange(int[] u, int[] v){
        // (x-a)^2 + (y-b)^2 = R^2 -> point (a, b) is at border
        // (x-a)^2 + (y-b)^2 < R^2 -> point (a, b) is inside the circle
        // (x-a)^2 + (y-b)^2 > R^2 -> point (a, b) is outside the circle
        return Math.pow(u[0]-v[0], 2) + Math.pow(u[1]-v[1], 2) <= Math.pow(u[2], 2);
    }

    private int dfs(int node, Map<Integer, List<Integer>> graph, Set<Integer> visited){
        if(visited.contains(node)) return 0;
        visited.add(node);
        int res = 0;
        for(int neigh: graph.get(node)){
            res += dfs(neigh, graph, visited);
        }
        return res + 1;
    }
}
class Solution {
public:
    double eucDis(int x1,int y1,int x2,int y2)
    {
        double temp=pow(x1-x2,2)+pow(y1-y2,2);
        return sqrt(temp);
    }
    void dfs(int node,vector<int>&vis,vector<int>graph[],int &c)
    {
        c++;
        vis[node]=1;
        for(auto i:graph[node])
        {
            if(!vis[i])
            {
                dfs(i,vis,graph,c);
            }
        }
    }
    int maximumDetonation(vector<vector<int>>& bombs) {
        
        int n=bombs.size();
        vector<int>graph[n+1];
        int i,j;
        for(i=0;i<n;i++)
        {
            bombs[i].push_back(i);
        }
        for(i=0;i<n;i++)
        {
            
            for(j=0;j<n;j++)
            {
                if(i==j)
                    continue;
                double dis1=eucDis(bombs[i][0],bombs[i][1],bombs[j][0],
                               bombs[j][1]);
                
                if(dis1<=bombs[i][2])
                {
                    int node1=bombs[i][3];
                    int node2=bombs[j][3];
                    graph[node1].push_back(node2);
                }
            }
        }
       
        int maxi=1;
        for(i=0;i<n;i++)
        {
            int c=0;
            if(graph[i].empty())
                continue;
            vector<int>vis(n+1,0);
            
            dfs(i,vis,graph,c);   
            maxi=max(maxi,c);
            
            
        }
        return maxi;
    }
};
/**
 * @param {number[][]} bombs
 * @return {number}
 */
var maximumDetonation = function(bombs) {
    if(bombs.length <= 1) return bombs.length;
    
    let adj = {}, maxSize = 0;
    const checkIfInsideRange = (x, y, center_x, center_y, radius) =>{
        return ( (x-center_x)**2 + (y-center_y)**2 <= radius**2 ) 
    }
	
	//CREATE ADJACENCY MATRIX
    for(let i = 0;i<bombs.length;i++){
        for(let j = i+1;j<bombs.length;j++){
            if(!adj[i]) adj[i] = [];
            if(!adj[j]) adj[j] = [];
            let bombOne = bombs[i];
            let bombTwo = bombs[j];
            let fir = checkIfInsideRange(bombOne[0], bombOne[1], bombTwo[0], bombTwo[1], bombOne[2]);     
            if(fir) adj[i].push(j);
            let sec = checkIfInsideRange(bombOne[0], bombOne[1], bombTwo[0], bombTwo[1], bombTwo[2]);
            if(sec) adj[j].push(i);
        }
    }
	
	//DEPTH FIRST SEARCH TO FIND ALL BOMBS TRIGGERED BY NODE
    const dfs = (node, visited)=>{
        let detonated = 1;
        visited[node] = true;
        let childs = adj[node] || []
        for(let child of childs){
            if(visited[child]) continue;
            detonated += dfs(child, visited)
        }
        maxSize = Math.max(maxSize, detonated)
        return detonated;
    }
    
    for(let i = 0 ;i<bombs.length;i++){
        dfs(i, {})
    }
    return maxSize
};
Detonate the Maximum Bombs