Created
September 13, 2019 04:10
-
-
Save Nimishkhurana/3b895c5ade0b251aaede5e4440038a64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<pair<int,int>> offset{{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,1},{-1,-1},{1,-1}}; | |
bool isSafe(int i, int j){ | |
if(i>=0 && j>=0 && i<SIZE && j<SIZE) | |
return true; | |
return false; | |
} | |
void dfs(int i, int j, int g[SIZE][SIZE], bool vis[SIZE][SIZE], int *count){ | |
if(!isSafe(i,j) || vis[i][j] || g[i][j]!=1) return; | |
vis[i][j] = true; | |
*count = *count+1; | |
for(int i=0;i<8;i++) | |
dfs(i+offset[i].first, j+offset[j].second,g,vis,count); | |
} | |
int findAreaUtil(int n, int m, int g[SIZE][SIZE], bool vis[SIZE][SIZE]){ | |
int area=0,max_area=0; | |
for(int i=0;i<SIZE;i++){ | |
for(int j=0;j<SIZE;j++){ | |
if(g[i][j]==1 && !vis[i][j]){ | |
area = 0; | |
dfs(i,j,g,vis,&area); | |
if(area>max_area) max_area=area; | |
} | |
} | |
} | |
return max_area; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment