C++ dfs
\n\nclass Solution {\npublic:\n    vector<vector<int> > g;\n    int n, m, c, mx, w, r, ans, itr;\n    unordered_set<int> s;\n    \n    int dfs(int i, int j){\n 
```\n\nclass Solution {\npublic:\n    vector<vector<int> > g;\n    int n, m, c, mx, w, r, ans, itr;\n    unordered_set<int> s;\n    \n    int dfs(int i, int j){\n        if(i<0 || i>=n || j<0 || j>=m || g[i][j]!=1)\n            return 0;\n        int ans=0;\n        if(i+1<n && g[i+1][j]==0){\n            s.insert((i+1)*m+j);\n            ans++;\n        }\n        if(i-1>=0 && g[i-1][j]==0){\n            s.insert((i-1)*m+j);\n            ans++;\n        }\n        if(j+1<m && g[i][j+1]==0){\n            s.insert(i*m+(j+1));\n            ans++;\n        }\n        if(j-1>=0 && g[i][j-1]==0){\n            s.insert(i*m+(j-1));\n            ans++;\n        }\n        g[i][j]=c;\n        ans+=dfs(i+1, j);\n        ans+=dfs(i-1, j);\n        ans+=dfs(i, j+1);\n        ans+=dfs(i, j-1);\n        return ans; // total number of walls needed to block this connected component\n    }\n    \n    int containVirus(vector<vector<int>>& grid) {\n        g=grid, n=g.size(), m=g[0].size(), ans=0;\n        while(true){\n            c=2, mx=0;\n            for(int i=0; i<n; i++){\n                for(int j=0; j<m; j++){\n                    if(g[i][j]==1){\n                        s.clear();\n                        int walls=dfs(i, j);\n                        if(mx<s.size()){\n                            mx=s.size();\n                            w=walls;\n                            r=c;\n                        }\n                        c++;\n                    }\n                }\n            }\n            if(mx==0)\n                break;\n            ans+=w;\n            for(int i=0; i<n; i++){\n                for(int j=0; j<m; j++){\n                    if(g[i][j]==r)\n                        g[i][j]=1e9;\n                    else if(g[i][j]>1 && g[i][j]!=1e9){\n                        g[i][j]=1;\n                        if(i+1<n && !g[i+1][j]) g[i+1][j]=1;\n                        if(i-1>=0 && !g[i-1][j]) g[i-1][j]=1;\n                        if(j+1<m && !g[i][j+1]) g[i][j+1]=1;\n                        if(j-1>=0 && !g[i][j-1]) g[i][j-1]=1;\n                    }\n                }\n            }\n        }\n        return ans;\n    }\n};\n\n```
['Depth-First Search', 'Graph', 'C', 'Matrix']