[C++] Disjoint Set Union -  Clean Code - "Template for most of DSU problem"
\n# Code\n\nclass DSU{\nprivate:\n    vector<int>Parent,Size;\npublic :\n    DSU(int n){\n        Parent.resize(n);\n        Size.resize(n);\n        for(int i=
\n# Code\n```\nclass DSU{\nprivate:\n    vector<int>Parent,Size;\npublic :\n    DSU(int n){\n        Parent.resize(n);\n        Size.resize(n);\n        for(int i=0;i<n;i++){\n            Parent[i]=i;\n            Size[i]=1;\n        }\n    }\n    int Find(int x){\n        if(x==Parent[x]) return x;\n        return Parent[x]=Find(Parent[x]);\n    }\n    bool Union(int x,int y){\n        x=Find(x);\n        y=Find(y);\n        if(x==y) return false;\n        if(Size[x]<Size[y]){\n            swap(x,y);\n        }\n        Parent[y] = x;\n        Size[x] += Size[y];\n        return true;\n    }\n};\nclass Solution {\npublic:\n    int findCircleNum(vector<vector<int>>& isConnected) {\n        int n=isConnected.size();\n        DSU dsu(n);\n        int ans=n;\n        for(int i=0;i<n;i++){\n            for(int j=i+1;j<n;j++){\n                if(isConnected[i][j] && dsu.Find(i)!=dsu.Find(j) ){\n                    ans-=1;\n                    dsu.Union(i,j);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']