C++ solution || Union Find Method
\nclass Solution {\npublic:\n    vector<int> parent, sz;\n\n    int find_set(int x){\n        if(parent[x] == x) return x;\n        return parent[x] = find_set(
```\nclass Solution {\npublic:\n    vector<int> parent, sz;\n\n    int find_set(int x){\n        if(parent[x] == x) return x;\n        return parent[x] = find_set(parent[x]);\n    }\n\n    bool make_union(int x, int y){\n        int a = find_set(x);\n        int b = find_set(y);\n        if(a == b) return true;\n        if(sz[a] < sz[b]) swap(a, b);\n        parent[b] = a;\n        sz[a] += sz[b];\n        return false;\n    }\n\n    int regionsBySlashes(vector<string>& grid) {\n        int n = grid.size()+1;                         // for 3x3 we need 4x4 matrix, so n = grid.size()+1\n        parent.resize(n*n);\n        sz.resize(n*n);\n        for(int i = 0; i<n*n; i++){\n            parent[i] = i;\n            sz[i] = 1;\n        }\n\n        vector<int> rank(n*n, -1);\n        int ans = 1;\n        for(int i = 0; i<n; i++){\n            for(int j = 0; j<n; j++){\n                if(i == 0 || j == 0 || i == n-1 || j == n-1){\n                    int y = i*n + j;\n                    make_union(0, y);                  // to make outerboundary as a cycle\n                }\n            }\n        }\n        for(int i = 0; i<grid.size(); i++){\n            string str = grid[i];\n            for(int j = 0; j<str.size(); j++){\n                if(str[j] == \'/\'){                     // if str[j] = \'/\' pt are ={ (i+1, j ) , ( i, j+1)}\n                    int x = (i+1)*n + j;\n                    int y = i*n + (j+1);\n                    if (make_union(x, y))\n                        ans++;\n                }\n                else if(str[j] == \'\\\\\'){               // if str[j] = \'\\\\\' pt are ={ (i, j ) , ( i+1, j+1)}\n                    int x = (i + 1) * n + (j+1);\n                    int y = i * n + (j);\n                    if(make_union(x, y)) ans++;\n                }                                      // for str[j] = \' \' just continue.\n            }\n        }\n        return ans;\n    }\n}; \n```
['Union Find', 'Graph', 'C', 'C++']