Wrong in this code?


#1

int Solution::black(vector &A) {
vector<vector> visited(A.size(),vector(A[0].size(),false));
int ans = 0;
for(int i = 0;i<A.size();i++)
{

    for(int j = 0;j<A[0].size();j++)
    {
        //cout<<i<<" "<<j<<endl;
        queue<pair<int,int>> shape;
        if(visited[i][j] == false && A[i][j] == 'X')
        {
            ans++;
            shape.push(make_pair(i,j));
            visited[i][j] = true;
            while(!shape.empty())
            {
                pair<int, int > current = shape.front();
                int x = current.first;
                int y = current.second;
                shape.pop();
                if(visited[x + 1][y] == false && A[x + 1][y] =='X' && x < A.size())
                {
                    shape.push(make_pair(x + 1,y));
                    visited[x + 1][y] = true;
                }
                if(visited[x][y+1] == false && A[x][y+1] =='X' && y <A[0].size())
                {
                    shape.push(make_pair(x,y+1));
                    visited[x][y+1] = true;
                }
                if(y>0 && visited[x][y -1] == false && A[x][y-1] =='X')
                {
                    shape.push(make_pair(x,y-1));
                    visited[x][y-1] = true;
                }
                if( x > 0 && visited[x-1][y] == false && A[x - 1][y] =='X' )
                {
                    shape.push(make_pair(x - 1,y));
                    visited[x-1][y] = true;
                }
            }
            
        }
        
    }
    
}
return ans;

}
what is wrong in this code??