第九行后面掉了一句
```cpp
a[r][c] = 1;
```
by caojiaming @ 2022-12-24 15:44:09
@[caojiaming](/user/775551) 好像改成 1-base 就可以过
```cpp
#include<bits/stdc++.h>
using namespace std;
char pic[100][100];
int a[100][100];
int n, m;
void dfs(int r, int c)
{
if(r<0||r>n+1||c<0||c>n+1||a[r][c]!=0) return;
a[r][c] = 1;
dfs(r + 1,c);
dfs(r - 1,c);
dfs(r,c + 1);
dfs(r,c - 1);
}
int main()
{
cin >> m;
n = m;
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> pic[i][j];
if(pic[i][j] == '0')
{
a[i][j] = 0;
}
else
{
a[i][j] = 2;
}
}
}
dfs(0,0);
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= n; j++)
{
if(a[i][j] == 0)
{
cout << "2 ";
}
else
{
cout << pic[i][j] << " ";
}
}
cout << '\n';
}
}
```
原因应该是 dfs 扫描的起点问题。
by Jerrlee✅ @ 2022-12-24 15:59:23