C++ BFS Solution, brief code and quite easy to understand
We just try to remove any one node from the initial nodes, and try to get the number of nodes infected without this node. The node which will result in the leas
We just try to remove any one node from the initial nodes, and try to get the number of nodes infected without this node. The node which will result in the least number of nodes infected is the result.\n\n```\nclass Solution {\npublic:\n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n        sort(initial.begin(), initial.end());\n        int res = INT_MAX, node = -1;\n        for (int i = 0; i < initial.size(); i++) {\n            int k = initial[i];\n            int count = getMalwareNodes(k, graph, initial);\n            //cout << k << \' \' << count << endl;\n            if (count < res) {\n                res = count;\n                node = k;\n            }\n        }\n        \n        return node;\n    }\nprivate:\n    int getMalwareNodes(int disable, vector<vector<int>>& graph, vector<int>& initial) {\n        int N = graph.size();\n\n        vector<bool> mask(N, false);\n        queue<int> q;\n        \n        for (int i = 0; i < initial.size(); i++) {\n            int k = initial[i];\n            if (k == disable) {\n                continue;\n            }\n\n            q.push(k);\n            mask[k] = true;\n        }\n        \n        while (!q.empty()) {\n            int n = q.front();\n            q.pop();\n\n            for (int i = 0; i < N; i++) {\n                if (i == n || i == disable) {\n                    continue;\n                }\n                if (graph[n][i] == 0 || mask[i]) {\n                    continue;\n                }\n                mask[i] = true;\n                q.push(i);\n            }\n        }\n        \n        int infected = 0;\n        for (int i = 0; i < N; i++) {\n            if (mask[i]) {\n                infected++;\n            }\n        }\n        \n        return infected; \n    }\n};\n```
[]