C++ DFS solution with Easy Explanation (Beats 90% submissions in one go)
Connected Components in a bidirectional Graph\nAs given in the question, we have n nodes. So we will make a visited array for n nodes. then we will start with o
# Connected Components in a bidirectional Graph\nAs given in the question, we have ```n``` nodes. So we will make a visited array for `n` nodes. then we will start with one node, and mark all its connected nodes as `visited=true`. So we will count only how many times we have to start this process. that will be our answer.\n\n```\nint findCircleNum(vector<vector<int>>& M) {\n\tint n=M.size(),ans=0;\n\tif(n==0) return 0;\n\n\tvector<bool>vis(n,false);\n\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tif(!vis[i])\n\t\t{\n\t\t\tans++;\n\t\t\tdfs(M,vis,i);\n\t\t}\n\t}\n\treturn ans;\n}\n\nvoid dfs(vector<vector<int>>& M, vector<bool>& vis, int i)\n{\n\tvis[i]=true;\n\tfor(int j=0;j<M.size();j++)\n\t\tif(M[i][j]==1 && !vis[j])\n\t\t\tdfs(M,vis,j);\n}\n```
['Depth-First Search', 'Graph', 'C']