```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> >a(32,vector<int>(32));
void dfs(int x,int y){
if (x >= 0 && x <= n + 1 && y >= 0 && y <= n + 1){
if (a[x][y] == 1 || a[x][y] == 3)
return;
else {
a[x][y] = 3;
dfs(x - 1,y);
dfs(x + 1,y);
dfs(x,y - 1);
dfs(x,y + 1);
}
}
}
int main(){
cin >> n;
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= n; j ++)
cin >> a[i][j];
}
dfs(0,0);
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= n; j ++){
if (a[i][j] == 3)
a[i][j] = 0;
else if (a[i][j] == 0)
a[i][j] = 2;
cout << a[i][j] << " ";
}
cout << "\n";
}
return 0;
}
```
@[sky_233](/user/1196571)
by Lg2307 @ 2024-03-30 12:06:08
@[Lg2307](/user/1034368) 好的谢谢大佬
by sky_233 @ 2024-03-30 17:13:48