Language: C++

#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
typedef pair<int, int> P;
const int INF = 100000000;
char maze[51][51];
int d[50][50];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int bfs(int H,int W) {
	int i, j, k, l, m, nx, ny;
	queue<P> que;
	for (i = 0; i < 50; i++) {
		for (j = 0; j < 50; j++) {
			d[i][j] = INF;
		}
	}
	que.push(P(0, 0));
	d[0][0] = 0;
	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == 49 && p.second == 49)
			break;
		for (i = 0; i < 4; i++) {
			nx = p.first + dx[i];
			ny = p.second + dy[i];

			if (nx >= 0 && nx < H&&ny >= 0 && ny < W&&d[nx][ny] == INF && maze[nx][ny] != '#') {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[W-1][H-1];
}



int main()
{
	int H, W,black;
	cin >> H >> W;
	int i, j, k;
  black=0;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> maze[i][j];
          if(maze[i][j]=='#')black++;
		}
	}
	k = bfs(H, W);
	if (k = INF)
		cout << "-1" << endl;
	else
		cout << H * W - k-black-1 << endl;
    return 0;
}



Compiler output:
a.cc:11:9: error: 'pair' does not name a type
   11 | typedef pair<int, int> P;
      |         ^~~~
a.cc: In function 'int bfs(int, int)':
a.cc:20:9: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
   20 |         queue<P> que;
      |         ^~~~~
      |         std::queue
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_queue.h:96:11: note: 'std::queue' declared here
   96 |     class queue
      |           ^~~~~
a.cc:20:15: error: 'P' was not declared in this scope
   20 |         queue<P> que;
      |               ^
a.cc:20:18: error: 'que' was not declared in this scope
   20 |         queue<P> que;
      |                  ^~~
a.cc:29:18: error: expected ';' before 'p'
   29 |                 P p = que.front();
      |                  ^~
      |                  ;
a.cc:31:21: error: 'p' was not declared in this scope
   31 |                 if (p.first == 49 && p.second == 49)
      |                     ^
a.cc:34:30: error: 'p' was not declared in this scope
   34 |                         nx = p.first + dx[i];
      |                              ^
a.cc: In function 'int main()':
a.cc:51:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   51 |         cin >> H >> W;
      |         ^~~
      |         std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:62:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   62 |                 cout << "-1" << endl;
      |                 ^~~~
      |                 std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:62:33: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   62 |                 cout << "-1" << endl;
      |                                 ^~~~
      |                                 std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:64:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   64 |                 cout << H * W - k-black-1 << endl;
      |                 ^~~~
      |                 std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:64:46: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   64 |                 cout << H * W - k-black-1 << endl;
      |                                              ^~~~
      |                                              std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~