simple DFS| On queries
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: O(Q*(dfs (avg of(O(N)))))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:(O(N+Q))\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nint n;\n    pair<bool,int> dfs(int s,vector<vector<int>>& g,vector<bool> &vis,map<int,int> &mp,int &sp){\n        vis[s]=true;\n        if(mp.find(s)!=mp.end())\n        {\n            return {false,0};\n        }\n        sp=0;\n        int ans=1;\n        bool kk=true;\n        for(int i=0;i<n;i++)\n        {\n            if(g[s][i]==1&&!vis[i])\n            {\n                auto z=dfs(i,g,vis,mp,sp);\n                if(z.first==true)\n                {\n                    ans+=z.second;\n                }\n                else{\n                    kk=false;\n                }\n            }\n        }\n        return {kk,ans};\n    }\n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n        n=graph.size();\n        vector<bool> vis(n,false);\n        map<int,int> mp;\n        int c=-1;\n        int ans=-1;\n        int q=initial.size();\n        for(int i=0;i<q;i++)\n        {\n            mp[initial[i]]=1;\n        }\n        sort(initial.begin(),initial.end());\n        for(auto i:initial){\n            cout<<i<<" ";\n            vector<bool> vis(n,false);\n            int sp=-1;\n            vis[i]=true;\n            int z=0;\n            for(int j=0;j<n;j++)\n            {\n                if(graph[i][j]==1&&!vis[j]&&i!=j)\n                {\n                    auto k=dfs(j,graph,vis,mp,sp);\n    \n                    if(k.first==true)\n                    {\n                        z+=k.second;\n                    }\n                }\n            }\n            cout<<z<<endl;\n            if(c<z)\n            {\n                c=z;\n                ans=i;\n                   \n            }\n        }\n         \n        return ans;   \n    }\n};\n```
['C++']