File tree Expand file tree Collapse file tree
BFS/2101.Detonate-the-Maximum-Bombs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using LL = long long ;
2+ class Solution {
3+ vector<int >next[100 ];
4+ public:
5+ int maximumDetonation (vector<vector<int >>& bombs)
6+ {
7+ int n = bombs.size ();
8+ for (int i=0 ; i<n; i++)
9+ for (int j=0 ; j<n; j++)
10+ {
11+ LL dx = bombs[i][0 ]-bombs[j][0 ];
12+ LL dy = bombs[i][1 ]-bombs[j][1 ];
13+ LL r = bombs[i][2 ];
14+ if (dx*dx+dy*dy<=r*r)
15+ next[i].push_back (j);
16+ }
17+
18+ int ret = 0 ;
19+ for (int s=0 ; s<n; s++)
20+ {
21+ queue<int >q;
22+ q.push (s);
23+ vector<int >visited (n);
24+ visited[s] = 1 ;
25+ while (!q.empty ())
26+ {
27+ int cur = q.front ();
28+ q.pop ();
29+ for (int i: next[cur])
30+ {
31+ if (visited[i]) continue ;
32+ q.push (i);
33+ visited[i] = 1 ;
34+ }
35+ }
36+ int count = 0 ;
37+ for (int i=0 ; i<n; i++)
38+ count+=visited[i];
39+ ret = max (count, ret);
40+ }
41+ return ret;
42+
43+ }
44+ };
You can’t perform that action at this time.
0 commit comments