[C++] Using bfs  {beginners code}
Pls upvote if you find this helpful  :)\n\nI\'m a beginner to graph theory and am finding it a bit difficult to grasp these concepts.Tried to learn union find b
***Pls upvote if you find this helpful  :)***\n\nI\'m a beginner to graph theory and am finding it a bit difficult to grasp these concepts.Tried to learn union find but couldn\'t understand it. It would be great if someone could help me understand it .Also if you have any other better method or can optimise this code then pls mention them in the comments.\n\nHere i have used the concept of bfs with a boolean  visited array and a queue q1. I have tried to count the components of the given graph.\n```\nclass Solution {\npublic:\n    int findCircleNum(vector<vector<int>>& M) {\n        int n=M.size();\n        if(n==0)return n;\n        int circles=0;\n        vector<bool> visited(n,false);  \n        for(int i=0;i<n;i++){\n            if(visited[i])continue;\n            queue<int> q1;\n            q1.push(i);\n            circles++;\n\n           while(!q1.empty()){               \n           int cur=q1.front();\n           q1.pop();\n           visited[cur]=true;\n               for(int j=0;j<M[cur].size();j++){\n                    if(visited[j]==false&&M[cur][j]==1){\n                    q1.push(j);\n                    visited[j]=true;\n                    }\n               }\n                    \n            }\n              \n            \n        }\n        return circles;\n    }\n};\n```
['Breadth-First Search', 'C', 'C++']