Beginner-friendly solution using C++ || DSU || Beats 99,47% Users
\n\n# Code\n\nclass Solution {\npublic:\n    int findCircleNum(vector<vector<int>>& isConnected) {\n        int n = isConnected.size();\n\n        vector<int> p
\n\n# Code\n```\nclass Solution {\npublic:\n    int findCircleNum(vector<vector<int>>& isConnected) {\n        int n = isConnected.size();\n\n        vector<int> parent(n);\n        for (int i = 0; i < n; i++)\n        {\n            parent[i] = i;\n        }\n\n        int res = n;\n\n        for (int i = 0; i < n; i++) \n        {\n            for (int j = i + 1; j < n; j++)\n            {\n                if (isConnected[i][j] == 1) \n                {\n                    int x = Find(i, parent);\n                    int y = Find(j, parent);\n\n                    if (x == y) continue;\n\n                    res--;\n                    if (x > y) \n                        parent[x] = y;\n                    else\n                        parent[y] = x;\n                }\n            }\n        }\n\n        return res;\n    }\n\nprivate:\n\n    int Find(int x, vector<int>& parent)\n    {\n        if (x != parent[x]) \n        {\n            parent[x] = Find(parent[x], parent);\n        }\n\n        return parent[x];\n    }\n};\n```
['C++']