有没有大佬帮我看看这错在哪里了

P1162 填涂颜色

hellocccl @ 2024-03-01 17:23:28

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
const int N=2e5+7;

int n;
map<int,int>mp;
set<int>st;
deque<int>dq;
int vis[35][35];
int a[35][35];
int baosou(int i,int j){
    if(i==1 or i==n or j==1 or j==n){
        return 0;
    }
    //上下左右分别遍历
    //不能走回头路
    //右
    if(a[i][j+1]==0 and vis[i][j+1]==0){
        vis[i][j+1]=1;
        baosou(i,j+1);
        vis[i][j+1]=0;

    }
    //下
    if(a[i+1][j]==0 and vis[i+1][j]==0){
        vis[i+1][j]=1;
        baosou(i+1,j);
        vis[i+1][j]=0;
    }
    //上
    if(a[i-1][j]==0 and vis[i-1][j]==0){
        vis[i-1][j]=1;
        baosou(i-1,j);
        vis[i-1][j]=0;
    }
    //左
    if(a[i][j-1]==0 and vis[i][j-1]==0){
        vis[i][j-1]=1;
        baosou(i,j-1);
        vis[i][j-1]=0;
    }
    return 1;
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }
    for(int i=2;i<=n-1;i++){
        for(int j=2;j<=n-1;j++){
            if(a[i][j]==0){
                if(baosou(i,j))a[i][j]=2;;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<'\n';
    }
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _=1;
    // cin>>_;
    while(_--){
        solve();
    }
}

|