3
int minDays(vector<vector<int>> &grid) {4
// if the graph has already greater than 1 components than ans is 05
// if the graph has any articulation point than ans is 18
int m = grid[0].size();11
vector<vector<int>> disc(n, vector<int>(m, 0));13
vector<vector<int>> low(n, vector<int>(m, 0));15
vector<vector<bool>> visited(n, vector<bool>(m, false));17
int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};18
// if ok is true means there is a articulation point in the graph21
function<void(int, int, int &, int)> dfs = [&](int x, int y, int &time, int p) {22
// mark the nodes as visited and update their low and disc time24
disc[x][y] = low[x][y] = time++;25
// for root if there are more than 1 recursive tree than root is a28
// going in all direction and making a dfs call29
for (int i = 0; i < 4; i++) {30
int newX = x + dir[i][0];31
int newY = y + dir[i][1];32
// if child cordinates are valid and there is a 1 at that point ans also34
if (newX >= 0 && newX < n && newY >= 0 && newY < m && grid[newX][newY] == 1 &&35
newX * m + newY != p) {36
if (!visited[newX][newY]) {37
dfs(newX, newY, time, x * m + y);38
// update the low time39
low[x][y] = min(low[x][y], low[newX][newY]);40
// checking whether [x,y] is articulation point or not43
} else if (disc[x][y] <= low[newX][newY]) {47
// updating the low time48
low[x][y] = min(low[x][y], disc[newX][newY]);52
// if root and more than 1 recurive tree formed than articulation point53
if (p == -1 && rootCall > 1) {57
// counting the number of 1's and making dfs call59
for (int i = 0; i < n; i++) {60
for (int j = 0; j < m; j++) {61
if (grid[i][j] == 1) {73
// if more than one components are formed76
// if onlu one component is formed and there is a articulation point79
// if total number of 1 is 182
} else if (to1 == 0) {83
// if total number of 1 is 0