c++ solution bfs
Referring: http://hehejun.blogspot.com/2018/10/leetcodeminimize-malware-spread-ii.html\n\n\nclass Solution {\npublic:\n    int minMalwareSpread(vector<vector<in
Referring: http://hehejun.blogspot.com/2018/10/leetcodeminimize-malware-spread-ii.html\n\n```\nclass Solution {\npublic:\n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n        int ans = 0, n = initial.size(), minCnt = graph.size(); \n        sort(initial.begin(), initial.end());\n        for(int i : initial) {\n            int cnt = bfs(graph, initial, i);\n            if(cnt < minCnt) minCnt = cnt, ans = i;\n        }\n        return ans;\n    }\n    \nprivate:\n    int bfs(vector<vector<int>>& graph, vector<int>& initial, int node) {\n        queue<int> q;\n        unordered_set<int> st = {node};\n        int cnt = 0;\n        for(int i : initial) if(i != node) q.push(i);\n        while(!q.empty()) {\n            int cur = q.front(); q.pop();\n            if(st.count(cur)) continue;\n            st.insert(cur); cnt++;\n            for(int i = 0; i < graph.size(); i++) if(i != cur && graph[cur][i]) q.push(i);\n        }\n        return cnt;\n    }\n};\n```
[]