#include #define _LIBCPP_DEBUG 0 using namespace std; typedef long long int ll; ll MOD = 1e9 + 7; int INF = 1 << 30; vector> MAP(1002,vector(1002,'#')); vector> dist(1002,vector(1002,INF)); int sy,sx,gy,gx; void bfs(){ queue qR; qR.push(sy); queue qC; qC.push(sx); dist[sy][sx]=0; int aR[4] = {1,0,-1,0}; int aC[4] = {0,1,0,-1}; while (!qR.empty()){ int ROW=qR.front(); qR.pop(); int COL=qC.front(); qC.pop(); for (int i = 0; i < 4; ++i) { if(MAP[ROW+aR[i]][COL+aC[i]]!='#' && dist[ROW+aR[i]][COL+aC[i]]==INF){ dist[ROW+aR[i]][COL+aC[i]] = dist[ROW][COL]+1; qR.push(ROW+aR[i]); qC.push(COL+aC[i]); } } } } int main(void){ int R,C; cin>>R>>C; cin>>sy>>sx; cin>>gy>>gx; for (int i = 1; i <= R; ++i) { for (int j = 1; j <= C; ++j) { cin>>MAP[i][j]; } } bfs(); cout<