<awangdev>1267. Count Servers that Communicate_2.java
private int dfs(int[][] grid, int i, int j, boolean[][] visited) {

        if (visited[i][j] || grid[i][j] == 0) return 0; 
            
        visited[i][j] = true;
        int count = 1;
        for (int x = 0; x < grid.length; x++) { 
            count += dfs(grid, x, j, visited);
        }
        for (int y = 0; y < grid[0].length; y++) { 
            count += dfs(grid, i, y, visited);
        }
        return count;
    }
private int sample_funcname ( int [ ] [ ] grid , int i , int j , boolean [ ] [ ] visited ) {
  if ( visited [ i ] [ j ] || grid [ i ] [ j ] == 0 ) return 0 ;
  visited [ i ] [ j ] = true ;
  int count = 1 ;
  for ( int x = 0 ;
  x < grid . length ;
  x ++ ) {
    count += dfs ( grid , x , j , visited ) ;
  }
  for ( int y = 0 ;
  y < grid [ 0 ] . length ;
  y ++ ) {
    count += dfs ( grid , i , y , visited ) ;
  }
  return count ;
}
