c++ solution union find
\nclass Solution {\npublic:\n    vector<int>parent;\n    int count;\n    int find(int x)\n    {\n        if(parent[x]==x)\n        {\n            return x;\n   
```\nclass Solution {\npublic:\n    vector<int>parent;\n    int count;\n    int find(int x)\n    {\n        if(parent[x]==x)\n        {\n            return x;\n        }\n        return parent[x]=find(parent[x]);\n    }\n    void Union(int x,int y)\n    {\n        x=find(x);\n        y=find(y);\n        if(x==y)\n        {\n            count++;\n        }\n        else\n        {\n            parent[x]=y;\n        }\n    }\n    int regionsBySlashes(vector<string>& mat) \n    {    \n        int n=mat.size();\n         count=1;\n        int dot=n+1;\n        parent=vector<int>(dot*dot+1,0);\n        for(int i=0;i<dot*dot+1;i++)\n        {\n            parent[i]=i;\n        }\n        for(int i=0;i<dot;i++)\n        {\n            for(int j=0;j<dot;j++)\n            {   \n                if(i==0||j==0||i==dot-1||j==dot-1)\n                {\n                    int cellx=i*dot+j;\n                    if(cellx!=0)\n                    Union(0,cellx);\n                }\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(mat[i][j]==\'/\')\n                {\n                    int x=(i)*dot+j+1;\n                    int y=(i+1)*dot+j;\n                    Union(x,y);\n                \n                }\n                else if(mat[i][j]==\'\\\\\')\n                {\n                    int x=i*dot+j;\n                    int y=(i+1)*dot+(j+1);\n                    Union(x,y);\n                }\n            }\n        }\n        return count;\n    }\n};\n```
['Union Find', 'C', 'C++']