Easy Visual Explanation
\n\n```\ntypedef vector vb;\ntypedef vector vvb;\ntypedef vector vvvb;\n\nclass Solution {\npublic:\n    void dfs(vector& grid, int i, int j, int type, vvvb& vi
![image](https://assets.leetcode.com/users/images/e766d37a-6fb0-4da8-a808-61dd77c0e335_1617350804.6259892.png)\n\n```\ntypedef vector<bool> vb;\ntypedef vector<vb> vvb;\ntypedef vector<vvb> vvvb;\n\nclass Solution {\npublic:\n    void dfs(vector<string>& grid, int i, int j, int type, vvvb& visited, int m, int n) {\n        if(i<0 or j<0 or i>=m or j>=n or visited[i][j][type]) return;\n        \n        visited[i][j][type] = true;\n        \n        switch(type) {\n            case 0:\n                dfs(grid, i-1, j, 2, visited, m, n);\n                break;\n            case 1:\n                dfs(grid, i, j-1, 3, visited, m, n);\n                break;\n            case 2:\n                dfs(grid, i+1, j, 0, visited, m, n);\n                break;\n            case 3:\n                dfs(grid, i, j+1, 1, visited, m, n);\n                break;\n        }\n        \n        if(grid[i][j] == \'\\\\\') dfs(grid, i, j, type^3, visited, m, n); \n        else if(grid[i][j] == \'/\') dfs(grid, i, j, type^1, visited, m, n);\n        else {\n            for(int t = 0; t<4; t++) {\n                if(t != type) dfs(grid, i, j, t, visited, m, n);\n            }\n        }\n    }\n    \n    int regionsBySlashes(vector<string>& grid) {\n     int m = grid.size(), n = grid[0].size();\n     vvvb visited(m, vvb(n, vb(4, false)));\n        \n     int regions = 0;\n        \n     for(int i=0; i<m; i++)\n         for(int j=0; j<n; j++)\n             for(int type = 0; type < 4; type++) {\n                 if(!visited[i][j][type]) {\n                     regions++;\n                     dfs(grid, i, j, type, visited, m, n);\n                 }\n             }\n         \n     return regions;    \n    }\n};
[]