Graph: Connecting the Dots + Image explanation!!! (No upscale + Tip)
Tip\nYou can defined the nodes as follow, and try to establish a graph.\n\nSo for a 2x2 grid here, we need to define 2x3 nodes.\n\n/!\ Dont forget the diagonal 
# Tip\nYou can defined the nodes as follow, and try to establish a graph.\n![image.png](https://assets.leetcode.com/users/images/cb9761ad-7414-43a1-bd87-213cbde0725b_1723282394.6061473.png)\nSo for a 2x2 grid here, we need to define 2x3 nodes.\n\n**/!\\ Dont forget the diagonal edges !!!**\nexample:\n![image.png](https://assets.leetcode.com/users/images/d8c432d2-9b7b-40c9-ba87-95f84e75522d_1723282585.7465706.png)\n(edges are in green)\n\n![image.png](https://assets.leetcode.com/users/images/cc8f16b4-a656-4d9b-99e5-7c2334fe5955_1723282697.1085112.png)\n\n# Final code:\n(I used DFS here, but can be solved with any graph techniques, such as BFS, Union find, etc.)\n\n```python []\nclass Solution:\n    def regionsBySlashes(self, grid: List[str]) -> int:\n        n = len(grid)\n        adj = collections.defaultdict(set)\n\n        def link(a, b):\n            adj[a].add(b)\n            adj[b].add(a)\n\n        for r in range(n-1):\n            for c in range(n):\n                if grid[r][c] == " ":\n                    link((r, c), (r, c+1))\n                if grid[r+1][c] == " ":\n                    link((r+1, c), (r+1, c+1))\n                if grid[r][c] != "/" and grid[r+1][c] != "\\\\":\n                    link((r, c), (r+1, c))\n                if grid[r][c] != "\\\\" and grid[r+1][c] != "/":\n                    link((r, c+1), (r+1, c+1))\n                if grid[r][c] == "/" and grid[r+1][c] == "/":\n                    link((r, c+1), (r+1, c))\n                if grid[r][c] =="\\\\" and grid[r+1][c] == "\\\\":\n                    link((r, c), (r+1, c+1))\n\n        def dfs(r, c):\n            for rr, cc in adj[(r, c)]:\n                if (rr, cc) not in seen:\n                    seen.add((rr, cc))\n                    dfs(rr, cc)\n\n\n        seen = set()\n        count = 0\n        for r in range(n):\n            for c in range(n+1):\n                if (r, c) in seen: continue\n                seen.add((r, c))\n                dfs(r, c)\n                count += 1\n        return count\n```
['Depth-First Search', 'Matrix', 'Python3']