#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x = 0 , t = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
{
t = -1;
}
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * t;
}
inline void write(int x)
{
if(x < 0)
{
putchar('-');
}
if(x > 9)
{
write(x / 10);
}
putchar(x % 10 + '0');
}
const int N = 1010;
int n , m;
int o , oo;
int vis[N][N];
int sum;
int dx[4] = {0 , 1 , 0 , -1};
int dy[4] = {-1 , 0 , 1 , 0};
char a[N][N];
struct node
{
int x;
int y;
};
void bfs(int x , int y)
{
queue <node> q;
memset(vis , 0 , sizeof(vis));
sum=0;
q.push({x , y });
vis[x][y]=1;
sum=1;
while(q.size())
{
node tmp = q.front();
int tx = tmp.x;
int ty = tmp.y;
q.pop();
for(int i = 0; i < 4; ++ i)
{
int ttx = tx + dx[i];
int tty = ty + dy[i];
if(ttx >= 1 && ttx <=n && tty >= 1 && tty <= n && a[ttx][tty] != a[tx][ty] && vis[ttx][tty] == 0)
{
q.push({ttx , tty });
vis[ttx][tty] = 1;
sum ++;
}
}
}
}
int main()
{
n = read() , m = read();
for(int i = 1;i <= n; ++ i)
{
for(int j = 1;j <= n; ++ j)
{
cin >> a[i][j];
}
}
while(m --)
{
sum = 0;
o = read() , oo = read();
bfs(o , oo);
write(sum);
cout << '\n';
}
return 0;
}
请各位大佬帮本蒟蒻调一下代码