BFS ,DFS and disjoint union solution
BFS SOLUTION : \n  \n\t  void bfs(vector> &graph,vector &visited,int src){\n        \n        queue qu;\n        qu.push(src);\n\n        while(qu.empty()==fals
**BFS SOLUTION :** \n  \n\t  void bfs(vector<vector<int>> &graph,vector<bool> &visited,int src){\n        \n        queue<int> qu;\n        qu.push(src);\n\n        while(qu.empty()==false){\n            int p = qu.front();\n            qu.pop();\n\n            if(visited[p]==true){\n                continue;\n            }\n\n            visited[p] = true;\n\n            for(int i = 0; i<graph.size() ;i++){\n                if(visited[i]==false and graph[p][i]==1){\n                    qu.push(i);\n                }\n            }\n\n        }\n    }\n    int findCircleNum(vector<vector<int>>& isConnected) {\n       \n        int cntr = 0;\n        vector<bool> visited(isConnected.size() , false);\n\n        for(int i = 0; i<isConnected.size();i++){\n            if(visited[i]==false){\n                bfs(isConnected,visited,i);\n                cntr++;\n            }\n        }\n\n        return cntr;\n    }\n\t\n**DFS SOLUTION**\n\n\n\t void dfs(vector<vector<int>> &isConnected,int i){\n\t\t\tisConnected[i][i] = 0;\n\t\t\tfor(int j = 0; j<isConnected[i].size() ; j++){\n\t\t\t\tif(isConnected[i][j]==1){\n\t\t\t\t\tisConnected[i][j] = 0; // mark as visited;\n\t\t\t\t\tif(isConnected[j][j]==1){\n\t\t\t\t\t\tdfs(isConnected,j);                       \n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint findCircleNum(vector<vector<int>>& isConnected) {\n\t\t\tint provinces = 0;\n\t\t\tfor(int i = 0; i<isConnected.size() ; i++){\n\t\t\t\tif(isConnected[i][i]==1){\n\t\t\t\t\tprovinces++;\n\t\t\t\t\tdfs(isConnected,i);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn provinces;\n\t\t}\n\n**UNION BY RANK  `&`  PATH COMPRESSION**\n\n\t   struct UnionFind{\n\t\t\tint *root;\n\t\t\tint *rank;\n\t\t\tint size;\n\n\t\t\tpublic:\n\t\t\t\tUnionFind(int size){\n\t\t\t\t\tthis->size = size;\n\t\t\t\t\troot = new int[size];\n\t\t\t\t\trank = new int[size];\n\n\t\t\t\t\tfor(int i = 0; i<size;i++){\n\t\t\t\t\t\troot[i] = i;\n\t\t\t\t\t\trank[i] = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t//          work in <O(log n)=> compression\n\t\t\t   int find(int x){\n\t\t\t\t   if(x==root[x]){\n\t\t\t\t\t   return x;\n\t\t\t\t   }\n\n\t\t\t\t   int p = find(root[x]);\n\n\t\t\t\t   root[x] = p;\n\t\t\t\t   return p;\n\t\t\t   }  \n\n\t\t\t\tvoid Union(int x,int y){\n\t\t\t\t\tint rootX = find(x);\n\t\t\t\t\tint rootY = find(y);\n\n\t\t\t\t\tif(rootX==rootY)return;\n\n\n\t\t\t\t\tif(rank[rootX] > rank[rootY]){\n\t\t\t\t\t\troot[rootY] = rootX;\n\t\t\t\t\t}else if(rank[rootX] < rank[rootY]){\n\t\t\t\t\t\troot[rootX] = rootY;\n\t\t\t\t\t}else{ // if size of both are equal\n\t\t\t\t\t\troot[rootY] = rootX;\n\t\t\t\t\t\trank[rootX] += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbool connected(int x,int y){\n\t\t\t\t\treturn find(x)==find(y);\n\t\t\t\t}\n\t\t};\n\t\tint findCircleNum(vector<vector<int>>& isConnected) {\n\t\t\tint n = isConnected.size();\n\t\t\tvector<int> LeaderVisit(n,false);\n\t\t\tUnionFind uf(n);\n\t\t\tint connect = 0;\n\t\t\tfor(int i = 0; i<n;i++){\n\t\t\t\tfor(int j = 0;j<n;j++){\n\t\t\t\t\tif(i!=j and isConnected[i][j]==1){\n\t\t\t\t\t\tint p1 = uf.find(i);\n\t\t\t\t\t\tint p2 = uf.find(j);\n\n\t\t\t\t\t\tif(p1!=p2){\n\t\t\t\t\t\t\tconnect++;\n\t\t\t\t\t\t\tuf.Union(i,j);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn n - connect;\n\t\t}
['Depth-First Search', 'Breadth-First Search', 'C++']