Language: C++

int dy[] = {0,1,0,-1};
int dp[50][50];

int bfs(){
    queue<P> que;
    que.push(P(0,0));
    flag[0][0] = true;
    while(!que.empty()){
        P pair;
        pair = que.front();
        int x = pair.first;
        int y = pair.second;

        if(pair.first==W-1 && pair.second==H-1) break;
        que.pop();

        for(int i=0;i<4;i++){
            int gx = x + dx[i];
            int gy = y + dy[i];
            if(gx<0 || gy <0 || gx>=W || gy>=H) continue;
            if(flag[gy][gx]==false) {
                que.push(P(gx, gy));
                dp[gy][gx] = dp[y][x] + 1;
                flag[gy][gx] = true;
            }
        }
    }
    return dp[H-1][W-1];
}


int main(){
    cin >> H >> W;
    char s[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            flag[i][j] = false;
            dp[i][j] = 0;
        }
    }
    int black_count=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> s[i][j];
            if(s[i][j]=='#'){
                flag[i][j]= true;
                black_count++;
            }
        }
    }
    dp[0][0] = 1;
    int count = bfs();
    if(count==0) cout <<"-1" <<"\n";
    else{
        int answer = H*W - count - black_count;
        cout << answer <<"\n";
    }
    return 0;
}


Compiler output:
a.cc: In function 'int bfs()':
a.cc:5:5: error: 'queue' was not declared in this scope
    5 |     queue<P> que;
      |     ^~~~~
a.cc:5:11: error: 'P' was not declared in this scope
    5 |     queue<P> que;
      |           ^
a.cc:5:14: error: 'que' was not declared in this scope
    5 |     queue<P> que;
      |              ^~~
a.cc:7:5: error: 'flag' was not declared in this scope
    7 |     flag[0][0] = true;
      |     ^~~~
a.cc:9:10: error: expected ';' before 'pair'
    9 |         P pair;
      |          ^~~~~
      |          ;
a.cc:10:9: error: 'pair' was not declared in this scope
   10 |         pair = que.front();
      |         ^~~~
a.cc:14:24: error: 'W' was not declared in this scope
   14 |         if(pair.first==W-1 && pair.second==H-1) break;
      |                        ^
a.cc:14:44: error: 'H' was not declared in this scope
   14 |         if(pair.first==W-1 && pair.second==H-1) break;
      |                                            ^
a.cc:18:26: error: 'dx' was not declared in this scope; did you mean 'gx'?
   18 |             int gx = x + dx[i];
      |                          ^~
      |                          gx
a.cc:20:37: error: 'W' was not declared in this scope
   20 |             if(gx<0 || gy <0 || gx>=W || gy>=H) continue;
      |                                     ^
a.cc:20:46: error: 'H' was not declared in this scope
   20 |             if(gx<0 || gy <0 || gx>=W || gy>=H) continue;
      |                                              ^
a.cc:28:15: error: 'H' was not declared in this scope
   28 |     return dp[H-1][W-1];
      |               ^
a.cc:28:20: error: 'W' was not declared in this scope
   28 |     return dp[H-1][W-1];
      |                    ^
a.cc: In function 'int main()':
a.cc:33:5: error: 'cin' was not declared in this scope
   33 |     cin >> H >> W;
      |     ^~~
a.cc:33:12: error: 'H' was not declared in this scope
   33 |     cin >> H >> W;
      |            ^
a.cc:33:17: error: 'W' was not declared in this scope
   33 |     cin >> H >> W;
      |                 ^
a.cc:37:13: error: 'flag' was not declared in this scope
   37 |             flag[i][j] = false;
      |             ^~~~
a.cc:44:20: error: 's' was not declared in this scope
   44 |             cin >> s[i][j];
      |                    ^
a.cc:46:17: error: 'flag' was not declared in this scope
   46 |                 flag[i][j]= true;
      |                 ^~~~
a.cc:53:18: error: 'cout' was not declared in this scope; did you mean 'count'?
   53 |     if(count==0) cout <<"-1" <<"\n";
      |                  ^~~~
      |                  count
a.cc:56:9: error: 'cout' was not declared in this scope; did you mean 'count'?
   56 |         cout << answer <<"\n";
      |         ^~~~
      |         count