C++ Union Find Solution  94.57% faster than other solutions
In this we consider making subsets of all friends group and return the value of number of such subsets.\nTo make a friends group subset initially we put\nfriend
In this we consider making subsets of all friends group and return the value of number of such subsets.\nTo make a friends group subset initially we put\nfriends[i] = i (i.e everyone is a friend of itself)\nthen as we perform union find operation we connect the elements if they do not have same friends initially .\neg .  points  1-3 , 2-4 , 3-5 are friends \nthen \nfriends[3] = 1 ; \nfriends[4] = 2 ;\nfriends[5] = 3 ;\nand friends[2] = 2 , friends[1] = 1;\nThen we count the number of elements with friends[i] = i because it showcases either it has no other friend or in a friends group subset one element would have this which is considered the initial point eg. points 1 and 2.\nHere is the solution ,\ni\'ve tried my best to explain it but if u guys have doubts , I\'ll be happy to answer them :)\n```\nclass Solution {\npublic:\n    vector<int>friends;\n \t\n    int find(int i)\n    {\n        return friends[i]==i?i:find(friends[i]);\n    }\n    int findCircleNum(vector<vector<int>>& M) {\n        \n        int n = M.size();\n        friends.resize(n);\n        for(int i = 0; i < n; i++){\n            friends[i] = i;\n        }\n        for(int i=0;i<n;i++)\n        {\n            for(int j = 0;j < n;j++)\n            {\n                if(M[i][j]==1)\n                {\n                    int x = find(i);\n                    int y = find(j);\n                    if(x != y)\n                    {\n                        friends[y] = x;\n                    }\n                }\n            }\n        }\n        int ans = 0;\n        for(int i = 0;i < n ;i++)\n        {\n            if(friends[i]==i)\n                ans++;\n        }\n        return ans;\n    }\n};\n```\n**Please Upvote if you like it ^_^**
['Union Find', 'C++']