为啥有错???
#include<bits/stdc++.h>
using namespace std;
int n,m,a[1001][1001],x,y,fx[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool b[1001][1001];
struct node{
int x,y,z;
};
int bfs(int x,int y,int z){
int cnt=0;
memset(b,true,sizeof(b));
queue<node>q;
node t;
t.x=x;
t.y=y;
t.z=z;
q.push(t);
while(!q.empty()){
t=q.front();
q.pop();
int nx,ny;
for(int i=0;i<4;i++){
node tt;
tt.x=t.x+fx[i][0];
tt.y=t.y+fx[i][1];
if(tt.x>=1&&tt.y>=1&&tt.x<=n&&tt.y<=n&&b[tt.x][tt.y]==true&&a[tt.x][tt.y]==(0-t.z)){
cnt++;
b[tt.x][tt.y]=false;
tt.z=0-t.z;
q.push(tt);
}
}
}
return cnt;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%1d",&x);
a[i][j]=x;
if(x==0){
a[i][j]=-1;
}
}
}
for(int i=1;i<=m;i++){
cin>>x>>y;
printf("%d\n",bfs(x,y,a[x][y]));
}
return 0;
}