luoguoj–p1162-fill the color

Problem URL:Fill The Color
This problem is a traditional DFS problem.But is surely have some fancy technique to solve this problem.
There are two ways to achieve that.First,is to search the border and then fill ‘2’ in each circles.This way is tough,because it is hard to judge the real border.However,the second way,we can just initially fill up all ‘2’ in the map,and then alter those ‘2’s that aren’t in circles.It is much more easier than the first one because it is easy to judge the border.
The Source code is showed below:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int map[50][50];
int n;
int vis[50][50];
void dfs_map(int i,int j){
  if(i>n+1 || i<0 || j>n+1 || j<0 || map[i][j]==1 || vis[i][j]==4){
    return;
  }
  map[i][j]=0;
  vis[i][j]++;
  dfs_map(i+1,j);
  dfs_map(i-1,j);
  dfs_map(i,j+1);
  dfs_map(i,j-1);
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cin>>map[i][j];
      if(map[i][j]==0) map[i][j]=2;
      vis[i][j]=0;
    }
  }
  dfs_map(0, 0);
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cout<<map[i][j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}