(arr, i, j, n, m)
bfs 标记
bfs 标记
bfs 标记
def b_inject(arr, i, j, n, m):
    """bfs 标记"""
    tmp = [[i,j]]
    while len(tmp)>0:
        i, j = tmp.pop()
        arr[i][j] = 2
        if i >= n or j >= m:
            break
        if i<n-1 and arr[i+1][j] == 1:
            tmp.append([i+1, j])
        if i>0 and arr[i-1][j] == 1:
            tmp.append([i-1, j])
        if j<m-1 and arr[i][j+1] == 1:
            tmp.append([i, j+1])
        if j>0 and arr[i][j-1] == 1:
            tmp.append([i, j-1])
def b_inject ( arr , i , j , n , m ) : tmp = [ [ i , j ] ] while len ( tmp ) > 0 : i , j = tmp . pop ( ) arr [ i ] [ j ] = 2 if i >= n or j >= m : break if i < n - 1 and arr [ i + 1 ] [ j ] == 1 : tmp . append ( [ i + 1 , j ] ) if i > 0 and arr [ i - 1 ] [ j ] == 1 : tmp . append ( [ i - 1 , j ] ) if j < m - 1 and arr [ i ] [ j + 1 ] == 1 : tmp . append ( [ i , j + 1 ] ) if j > 0 and arr [ i ] [ j - 1 ] == 1 : tmp . append ( [ i , j - 1 ] )