#include #include using namespace std; int find(int* parent,int val) { if(parent[val]!=val) parent[val]=find(parent,parent[val]);//find the leader of the group of this node return parent[val]; } void unionSet(int* parent,int a,int b) { int ap = find(parent,a); int bp = find(parent,b); if(ap!=bp) parent[bp]=ap; //make 'a's parent as the leader of b's group as well. } int countNumberOfComponents(vector>& M) { int n = M.size(); int parent[n]; //stores parent for each node for(int i=0;i > adjacencyMatrix(vertices, vector(vertices,0)); for(int i=0;i