Easy C++ DFS Solution
\nvoid dfs(vector<vector<int>>&M,vector<vector<int>>& vis,int r,int c){\n\tif(r<0 || r> M.size() || c<0 || c> M.size()) return ;\n\tvis[r][c]=1;\n\tvis[c][r]=1;
```\nvoid dfs(vector<vector<int>>&M,vector<vector<int>>& vis,int r,int c){\n\tif(r<0 || r> M.size() || c<0 || c> M.size()) return ;\n\tvis[r][c]=1;\n\tvis[c][r]=1;\n\tfor(int i=0;i<M[0].size();i++){\n\t\tif(!vis[c][i] && M[c][i] == 1) dfs(M,vis,c,i);\n\t}\n\treturn ;\n}\nint findCircleNum(vector<vector<int>>& M) {\n\tint n=M.size();\n\tint ans=0;\n\tvector<vector<int>> vis(n,vector<int>(n,0));\n\tfor(int i=0;i<n;i++){\n\t\tfor(int j=0;j<n;j++){\n\t\t\tif(!vis[i][j] && M[i][j] == 1) {\n\t\t\t\tdfs(M,vis,i,j);\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t}\n\treturn ans;\n}\n```
[]