

- 문제 이해 :
1. 가중치가 모두 같은 경로를 탐색하며 , 최소 일수를 구하는 것이기 때문 -> BFS로 풀이한다.
2. 상자의 크기는 M*N // 문제를 똑바로 안읽고 의식의 흐름에 따라 N*M으로 입력받아서.. 시간이 걸렸다. 
내가 작성한 코드
#include <iostream>
#include <queue>
using namespace std;
int map[1001][1001], ch[1001][1001];
int main(){
    int n, m, a, ck=0, chz = 0 ,x, y, day=0;
    
    int dx[4] = {0 , 1, 0 ,-1};
    int dy[4] = {1, 0, -1, 0};
    queue<pair<int, int>> Q;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            cin >> a;
            map[i][j] = a;
            
            if(a == 1) {
                Q.push(make_pair(i, j));
                ch[i][j] = 1;
            }
            
            if(a == 0){ chz = 1;}
        }
    }
    
    if(chz == 0){ cout << 0; return 0;}
    while(!Q.empty()){
        x = Q.front().first;
        y = Q.front().second;
        Q.pop();
        for(int i=0; i<4; i++){
            if(x+dx[i] < 0 || x+dx[i] >= m || y+dy[i]<0 || y+dy[i] >= n) continue;
            
            
            if(ch[x+dx[i]][y+dy[i]] == 0 && map[x+dx[i]][y+dy[i]] == 0){
            
                Q.push(make_pair(x+dx[i], y+dy[i]));
                
                ch[x+dx[i]][y+dy[i]] = ch[x][y] + 1;
                map[x+dx[i]][y+dy[i]] = 1;
            }
        }
    }
    
    
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            if(map[i][j] == 0 ){ cout << -1; return 0;}
        }
    }
    
    cout << ch[x][y] -1 << endl;
    return 0;
}