DFS | C++ | O(n^2)
ApproachWe want to find the node that does maximum damage through a path that does not contain another infected node.This is because if curr node is removed fro
# Approach
We want to find the node that does maximum damage through a path that does not contain another infected node.

This is because if curr node is removed from the graph, we want to find the max damage that is prevented, given no other infected node can contribute to the damage.

# Complexity
- Time complexity:
O(n^2)

- Space complexity:
O(n)

# Code
```cpp []
class Solution {
public:
    void traverse(int i,int color,vector<vector<int>>& graph,unordered_set<int>* visited,vector<int>& clean)
    {
        visited[i].insert(color);
        for(int j=0;j<graph.size();j++)
        {
            if(graph[i][j]&&clean[j]&&visited[j].find(color)==visited[j].end())
                traverse(j,color,graph,visited,clean);
        }
    }
    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {
        int n=graph.size();
        unordered_set<int> visited[n];
        vector<int> clean(n,1);
        for(auto i: initial)
            clean[i]=0;
        for(auto i: initial)
        {
            traverse(i,i,graph,visited,clean);
        }
        int maxSpread=INT_MIN;
        int ans;
        for(auto i: initial)
        {
            int spread=0;
            for(int j=0;j<n;j++)
            {
                if(visited[j].find(i)!=visited[j].end()&&visited[j].size()==1)
                    spread++;
            }
            if(spread>maxSpread)
            {
                maxSpread=spread;
                ans=i;
            }
            else if(spread==maxSpread)
                ans=min(ans,i);
        }
        return ans;
    }
};
```
['C++']