DFS
\nclass Solution {\npublic:\n    int dfs(int node,int rem,vector<int>&vis,vector<vector<int>>&adj)\n    {\n        vis[node]=1;\n        if(node==rem)return 0;\
```\nclass Solution {\npublic:\n    int dfs(int node,int rem,vector<int>&vis,vector<vector<int>>&adj)\n    {\n        vis[node]=1;\n        if(node==rem)return 0;\n        int ans=0;\n        ans++;\n        for(auto child:adj[node])\n        {\n            if(vis[child]==false && child!=rem)\n            {\n                ans+=dfs(child,rem,vis,adj);\n            }\n        }\n        return ans;\n    }\n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n        int n=graph.size();\n        vector<vector<int>>adj(n,vector<int>());\n        sort(initial.begin(),initial.end());\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(i==j)continue;\n                if(graph[i][j])\n                {\n                    adj[i].push_back(j);\n                }\n            }\n        }\n        \n        int ans_node=0,ans_val=n;\n        \n        for(int M=0;M<initial.size();M++)\n        {\n            int i=initial[M];\n            vector<int>vis(n);\n            int temp=0;\n            for(int j=0;j<initial.size();j++){\n                int node=initial[j];\n                if(vis[node]==0)\n                {\n                    temp+=dfs(node,i,vis,adj);\n                }\n            }\n            if(temp<ans_val)\n                ans_node=i,ans_val=temp;\n        }\n        \n        return ans_node;\n    }\n};\n```
[]