My simple C++ solution gives segmentation fault

Comment bohere.void Solution::setZeroes(vector<vector > &A)
{
long long i,j;
long long m=A.size();
long long n= A[0].size();

int flagr=0;
int flagc=0;

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==0&&A[i][j]==0)
flagr=1;
if(j==0&&A[i][j]==0)
flagc=1;

  if(A[i][j]==0)
  {
  A[i][0]=1;
  A[0][j]=1;
  }
    
}

}

for(i=1;i<n;i++)
{
for(j=1;j<n;j++)
{

if(A[i][0]==1||A[0][j]==1)
A[i][j]=0;

}

}

//cout<<flagr;
//cout<<flagc;

if(flagr)
{
for(j=0;j<n;j++)
A[0][j]=0;
}

if(flagc)
{
for(i=0;i<n;i++)
A[i][0]=0;
}

}

Click here to start solving coding interview questions