#include #include using namespace std; class Solution { public: int maxAreaOfIsland(vector >& grid); }; int DFS(int i, int j, vector < vector > &g) { int c; if (g[i][j] == 1) { g[i][j] = 0; c = 1; if (i != 0) c += DFS(i-1, j, g); if (i+1 != g.size()) c += DFS(i+1, j, g); if (j != 0) c += DFS(i, j-1, g); if (j+1 != g[0].size()) c += DFS(i, j+1, g); return c; } return 0; } int Solution::maxAreaOfIsland(vector >& g) { int i, j, cs; int max = 0; for (i = 0; i < g.size(); i++) { for (j = 0; j < g[0].size(); j++) { if (g[i][j] == 1) { cs = DFS(i, j, g); if (cs > max) max = cs; } } } return max; } /* To use the main, enter row cols and then the grid. */ int main() { int r, c, n; int i, j; vector < vector < int > > g; Solution s; cin >> r >> c; g.resize(r); for (i = 0; i < r; i++) { for (j = 0; j < c; j++) { cin >> n; g[i].push_back(n); } } n = s.maxAreaOfIsland(g); cout << n << endl; }