你的 dfs 为什么从 $(0, 0)$ 开始
by whhsteven @ 2022-12-26 01:54:03
@[whhsteven](/user/118109) 你看看我这个dfs内函数的写法
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[35][35],vist[35][35];
long long n;
void dfs(int i,int j){
if(i<0||j<0||i>n+1||j>n+1||vist[i][j]!=0){
return;
}
vist[i][j]=1;
dfs(i-1,j);
dfs(i+1,j);
dfs(i,j+1);
dfs(i,j-1);
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
if(a[i][j]==0){
vist[i][j]=0;
}else{
vist[i][j]=2;
}
}
}
dfs(0,0);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(vist[i][j]==0){
cout<<"2"<<" ";
}else{
cout<<a[i][j]<<" ";
}
}
cout<<endl;
}
return 0;
}
```
by _Mikasa @ 2023-03-01 20:09:09