Brute-Force BFS across All The Infected Nodes One By One
Code
# Code
```cpp  []
class Solution {
public:
    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& in) {
        int n = graph.size();
        vector <vector<int>> adj(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (graph[i][j] == 1) {
                    adj[i].push_back(j);
                }
            }
        }
        int mn = INT_MAX;
        int idx = -1;
        sort(in.begin(),in.end());
        for (int i = 0; i < in.size(); i++) {
            queue<int>q;
            vector<int>vis(n,0);
            for (int j = 0; j < in.size(); j++) {
                if (in[j] != in[i]) {
                    q.push(in[j]);
                    vis[in[j]] = 1;
                }
            }
            while (!q.empty()) {
                int node = q.front();
                q.pop();
                for (int nei : adj[node]) {
                    if (nei != in[i] && vis[nei] == 0) {
                        vis[nei] = 1;
                        q.push(nei);
                    }
                }
            }
            int cnt = 0;
            for (int j = 0; j < n; j++) {
                if (vis[j] == 1) cnt++; 
            }
            cout << cnt << endl;
            if (mn > cnt) {
                mn = min(mn , cnt);
                idx = in[i];
            }
        }
        return idx;
    }
};
```
![download.jpeg](https://assets.leetcode.com/users/images/2e1e55d7-8b22-42bb-b45b-25512fcdc41a_1739054978.3134785.jpeg)

['Breadth-First Search', 'Graph', 'C++']