-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2101.cpp
More file actions
35 lines (33 loc) · 1.1 KB
/
Copy path2101.cpp
File metadata and controls
35 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public:
int maximumDetonation(vector<vector<int>> &bombs) {
vector<vector<int>> adj(bombs.size());
for (int i = 0; i < bombs.size(); i++) {
for (int j = i + 1; j < bombs.size(); j++) {
double dist = sqrt(pow(bombs[i][0] - bombs[j][0], 2) + pow(bombs[i][1] - bombs[j][1], 2));
if (dist <= bombs[i][2]) adj[i].push_back(j);
if (dist <= bombs[j][2]) adj[j].push_back(i);
}
}
int maxi = INT_MIN;
for (int i = 0; i < bombs.size(); i++) {
vector<bool> visited(bombs.size(), false);
int count = 0;
stack<int> st;
st.push(i);
visited[i] = true;
while (!st.empty()) {
int root = st.top();
st.pop();
count++;
for (int c : adj[root])
if (!visited[c]) {
visited[c] = true;
st.push(c);
}
}
maxi = max(maxi, count);
}
return maxi;
}
};