bfs
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n        const int n = graph.size();\n        sort(initial.begin(), initial.end());\n        int res = 0;\n        int cnt = n + 1;\n        for (const int m: initial)\n        {\n            vector<vector<int>> gh(n);\n            queue<int> q;\n            vector<bool> visited(n);\n            for (const int w: initial)\n            {\n                if (m == w)\n                    continue;\n                q.push(w);\n                visited[w] = true;\n            }\n            for (int i = 0; i < n; ++ i)\n            {\n                for (int j = 0; j < n; ++ j)\n                {\n                    if (graph[i][j] == 1 && i != m && j != m)\n                    {\n                        gh[i].push_back(j);\n                    }\n                }\n            }\n            const int count = minMalwareSpread(gh, q, visited);\n            if (count < cnt)\n            {\n                res = m;\n                cnt = count;\n            }\n        }\n        return res;\n    }\n    int minMalwareSpread(const vector<vector<int>>& graph, queue<int>& q, vector<bool>& visited)\n    {   \n        while (!q.empty())\n        {\n            const int n = q.size();\n            for (int i = 0; i < n; ++ i)\n            {\n                const int node = q.front();\n                q.pop();\n                for (const int next: graph[node])\n                {\n                    if (visited[next])\n                        continue;\n                    visited[next] = true;\n                    q.push(next);\n                }\n            }\n        }\n        return count(visited.cbegin(), visited.cend(), true);      \n    }\n};\n```
['C++']