leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2101.cpp (1127B)


0 class Solution { 1 public: 2 int maximumDetonation(vector<vector<int>> &bombs) { 3 vector<vector<int>> adj(bombs.size()); 4 for (int i = 0; i < bombs.size(); i++) { 5 for (int j = i + 1; j < bombs.size(); j++) { 6 double dist = sqrt(pow(bombs[i][0] - bombs[j][0], 2) + pow(bombs[i][1] - bombs[j][1], 2)); 7 if (dist <= bombs[i][2]) adj[i].push_back(j); 8 if (dist <= bombs[j][2]) adj[j].push_back(i); 9 } 10 } 11 12 int maxi = INT_MIN; 13 for (int i = 0; i < bombs.size(); i++) { 14 vector<bool> visited(bombs.size(), false); 15 int count = 0; 16 stack<int> st; 17 st.push(i); 18 visited[i] = true; 19 while (!st.empty()) { 20 int root = st.top(); 21 st.pop(); 22 count++; 23 for (int c : adj[root]) 24 if (!visited[c]) { 25 visited[c] = true; 26 st.push(c); 27 } 28 } 29 maxi = max(maxi, count); 30 } 31 32 return maxi; 33 } 34 };