<p>An <code>n x n</code> grid is composed of <code>1 x 1</code> squares where each <code>1 x 1</code> square consists of a <code>&#39;/&#39;</code>, <code>&#39;\&#39;</code>, or blank space <code>&#39; &#39;</code>. These characters divide the square into contiguous regions.</p>

<p>Given the grid <code>grid</code> represented as a string array, return <em>the number of regions</em>.</p>

<p>Note that backslash characters are escaped, so a <code>&#39;\&#39;</code> is represented as <code>&#39;\\&#39;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/1.png" style="width: 200px; height: 200px;" />
<pre>
<strong>Input:</strong> grid = [&quot; /&quot;,&quot;/ &quot;]
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/2.png" style="width: 200px; height: 198px;" />
<pre>
<strong>Input:</strong> grid = [&quot; /&quot;,&quot;  &quot;]
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 3:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/4.png" style="width: 200px; height: 200px;" />
<pre>
<strong>Input:</strong> grid = [&quot;/\\&quot;,&quot;\\/&quot;]
<strong>Output:</strong> 5
<strong>Explanation: </strong>Recall that because \ characters are escaped, &quot;\\/&quot; refers to \/, and &quot;/\\&quot; refers to /\.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == grid.length == grid[i].length</code></li>
	<li><code>1 &lt;= n &lt;= 30</code></li>
	<li><code>grid[i][j]</code> is either <code>&#39;/&#39;</code>, <code>&#39;\&#39;</code>, or <code>&#39; &#39;</code>.</li>
</ul>

class Solution {
public:
vector<int> dx = {0,0,1,-1};
vector<int> dy = {1,-1,0,0};
bool ok(int x,int y, int n, int m)
{
    return x>=0 and y>=0 and x<n and y<m;
}
    void bfs(int i, int j, vector<vector<int>>& vis, vector<vector<int>>& grid)
    {
        // cout<<i<<" "<<j<<endl;
        vis[i][j] = 1;
        queue<pair<int,int>> q;
        q.push({i,j});
        while(!q.empty())
        {
            pair<int,int> idx = q.front();
            int x = q.front().first;
            int y = q.front().second;
            cout<<x<<" "<<y<<endl;
            q.pop();
            for(int i=0;i<4;i++)
            {
                int newx = x+dx[i];
                int newy = y+dy[i];
                if(ok(newx,newy,grid.size(),grid[0].size()))
                {
                    if(!vis[newx][newy] and grid[newx][newy]==0)
                    {
                        vis[newx][newy] = 1;
                        q.push({newx,newy});
                    }
                }
            }
        }
    }
    int regionsBySlashes(vector<string>& grid) {
        int n = grid.size();
      vector<vector<int>> new_grid(3*n,vector<int>(3*n));  
      int row = 0;
      int col = 0;
      for(int i=0;i<grid.size();i++)
      {
        string s = grid[i];
        cout<<s<<endl;
        int j=0;
        cout<<s.size()<<endl;
        while(j<s.size())
        {
            // cout<<j<<" ";
            char c = s[j];
            // cout<<c<<endl;
            if(c == ' ')
            {
                new_grid[row][col] = 0;
                new_grid[row][col+1] = 0;
                new_grid[row][col+2] = 0;
                new_grid[row+1][col]=0;
                new_grid[row+1][col+1] = 0;
                new_grid[row+1][col+2] = 0;
                new_grid[row+2][col] = 0;
                new_grid[row+2][col+1] = 0;
                new_grid[row+2][col+2]=0;
                col+=3;
                j++;
            }
            else if(c == '/')
            {
                cout<<row<<" "<<col<<endl;
                new_grid[row][col] = 0;
                new_grid[row][col+1] = 0;
                new_grid[row][col+2] = 1;
                new_grid[row+1][col]=0;
                new_grid[row+1][col+1] = 1;
                new_grid[row+1][col+2] = 0;
                new_grid[row+2][col] = 1;
                new_grid[row+2][col+1] = 0;
                new_grid[row+2][col+2]=0;
                col+=3;
                j++;
            }
            else if(c == '\\')
            {
                // cout<<j<<" bole to "<<" ";
                j++;
                new_grid[row][col] = 1;
                new_grid[row][col+1] = 0;
                new_grid[row][col+2] = 0;
                new_grid[row+1][col]=0;
                new_grid[row+1][col+1] = 1;
                new_grid[row+1][col+2] = 0;
                new_grid[row+2][col] = 0;
                new_grid[row+2][col+1] = 0;
                new_grid[row+2][col+2]=1;
                col+=3;
                // cout<<"new j is "<<j<<" ";
            }
        }
        row+=3;
        col=0;
        cout<<endl;
      }
      for(vector<int> row:new_grid)
      {
        for(int ele:row)
        cout<<ele<<" ";
        cout<<endl;
      }
      vector<vector<int>> vis(3*n,vector<int>(3*n,0));
      int count = 0;
      for(int i=0;i<new_grid.size();i++)
      {
        for(int j=0;j<new_grid[0].size();j++)
        {
            if(new_grid[i][j] == 0)
            {
                if(!vis[i][j])
                bfs(i,j,vis,new_grid),count++;
            }
        }
      }
      return count;
    }
};
23071