class Solution {
public:
int dir[4][2] = {0,1,0,-1,-1,0,1,0};
int m=0,n=0;
int result = 0;
int tmp_result = 0;
void dfs(vector<vector<int>>& grid , vector<vector<bool>> &path , int x ,int y)
{
for(int i=0 ; i<4 ;i++)
{
int next_x = x + dir[i][0];
int next_y = y + dir[i][1];
if(next_x<0 || next_x>=m || next_y<0 || next_y>=n) continue;
if(grid[next_x][next_y] == 1 && path[next_x][next_y] == false)
{
tmp_result++;
path[next_x][next_y] = true;
dfs(grid,path,next_x,next_y);
}
}
}
int maxAreaOfIsland(vector<vector<int>>& grid) {
m = grid.size();
n = grid[0].size();
vector<vector<bool>> path(m , vector<bool>( n , false ));
for(int i=0 ; i<m ;i++)
{
for(int j=0 ; j<n ;j++)
{
if(grid[i][j] == 1 && path[i][j] == false)
{
path[i][j] = true;
tmp_result = 1;
dfs(grid,path,i,j);
if(tmp_result > result) result =tmp_result;
}
}
}
return result;
}
};