Brute Force | Beginner's Solution
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```cpp []\nclass Solution {\npublic:\n    int n;\n    void dfs(int node, vector<vector<int>>&adj, vector<int>&curr,vector<int>&vis){\n        vis[node]=1;\n        curr.push_back(node);\n        for(auto x:adj[node]){\n            if(vis[x]==1) continue;\n            dfs(x,adj,curr,vis);\n        }\n    }\n    int valid(vector<vector<int>>&adj, vector<int>&ini){\n        set<int>st(ini.begin(),ini.end());\n        set<int>answer;\n        for(int i=0;i<ini.size();i++){\n            vector<int>curr,vis(n,0);\n            dfs(ini[i],adj,curr,vis);\n            for(int i=0;i<curr.size();i++){\n                if(st.find(curr[i])==st.end()){\n                    answer.insert(curr[i]);\n                }\n            }\n        }\n        return answer.size();\n    }\n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& ini) {\n        n = graph.size();\n        int ans = INT_MAX;\n        int curr=INT_MAX;\n        sort(ini.begin(),ini.end());\n        for (int k = 0; k < ini.size(); k++) {\n            vector<vector<int>> adj(n);\n            for (int i = 0; i < n; i++) {\n                if (i == ini[k])\n                    continue;\n                for (int j = 0; j < i; j++) {\n                    if (j == ini[k])\n                        continue;\n                    if (graph[i][j] == 1) {\n                        adj[i].push_back(j);\n                        adj[j].push_back(i);\n                    }\n                }\n            }\n            for(int i=0;i<n;i++){\n                for(auto x:adj[i]){\n                    cout<<i<<" "<<x<<endl;\n                }\n            }            \n            if(valid(adj,ini)<curr){\n                curr=valid(adj,ini);\n                ans=ini[k];\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']