Language: C++

#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

#define MAX 30
#define INF 1000
int wn,hn;
int d[MAX][MAX];
bool w[MAX][MAX]; //w,h ?¨??£?
bool h[MAX][MAX]; //????£?
vector< pair<int, int> > nextlist; //x,y


void reset() {
	for (int i = 0; i < wn; i++) {
		for (int j = 0; j < hn; j++) {
			d[i][j] = INF;
		}
	}
}

bool sortRule(pair<int, int> left, pair<int, int> right) {
	return d[left.first][left.second] < d[right.first][right.second];
}


void maze(pair<int,int> pos) {
	nextlist.erase(nextlist.begin());
	//???
	if (pos.second > 0) {
		if (!w[pos.first][pos.second - 1] && d[pos.first][pos.second - 1] > d[pos.first][pos.second] + 1) {
			d[pos.first][pos.second - 1] = d[pos.first][pos.second] + 1;
			nextlist.push_back(pair<int, int>::pair(pos.first, pos.second - 1));
		}
	}

	//???
	if (pos.first > 0) {
		if (!h[pos.first - 1][pos.second] && d[pos.first - 1][pos.second] > d[pos.first][pos.second] + 1) {
			d[pos.first - 1][pos.second] = d[pos.first][pos.second] + 1;
			nextlist.push_back(pair<int, int>::pair(pos.first - 1, pos.second));
		}
	}

	//???
	if (pos.second < hn-1) {
		if (!w[pos.first][pos.second] && d[pos.first][pos.second + 1] > d[pos.first][pos.second] + 1) {
			d[pos.first][pos.second + 1] = d[pos.first][pos.second] + 1;
			nextlist.push_back(pair<int, int>::pair(pos.first, pos.second + 1));
		}
	}

	//???
	if (pos.first < wn -1) {
		if (!h[pos.first][pos.second] && d[pos.first + 1][pos.second] > d[pos.first][pos.second] + 1) {
			d[pos.first + 1][pos.second] = d[pos.first][pos.second] + 1;
			nextlist.push_back(pair<int, int>::pair(pos.first + 1, pos.second));
		}
	}

	if (nextlist.size() > 0) {
		sort(nextlist.begin(), nextlist.end(), sortRule);
		maze(nextlist[0]);

	}
}



int main() {
	cin >> wn >> hn;
	while (wn + hn) {
		reset();
		for (int i = 0; i < hn-1; i++) {
			for (int j = 0; j < wn-1; j++) {
				cin >> h[j][i];
			}
			for (int j = 0; j < wn; j++) {
				cin >> w[j][i];
			}
		}
		for (int j = 0; j < wn - 1; j++) {
			cin >> h[j][hn - 1];
		}

		d[0][0] = 1;
		nextlist.push_back(pair<int, int>::pair(0, 0));
		maze(nextlist[0]);

		if (d[wn - 1][hn - 1] == INF) {
			cout << 0 << endl;
		}
		else {
			cout << d[wn - 1][hn - 1] << endl;
		}

		cin >> wn >> hn;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void maze(std::pair<int, int>)':
a.cc:38:64: error: cannot call constructor 'std::pair<int, int>::pair' directly [-fpermissive]
   38 |                         nextlist.push_back(pair<int, int>::pair(pos.first, pos.second - 1));
      |                                            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:38:64: note: for a function-style cast, remove the redundant '::pair'
a.cc:46:64: error: cannot call constructor 'std::pair<int, int>::pair' directly [-fpermissive]
   46 |                         nextlist.push_back(pair<int, int>::pair(pos.first - 1, pos.second));
      |                                            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:64: note: for a function-style cast, remove the redundant '::pair'
a.cc:54:64: error: cannot call constructor 'std::pair<int, int>::pair' directly [-fpermissive]
   54 |                         nextlist.push_back(pair<int, int>::pair(pos.first, pos.second + 1));
      |                                            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:54:64: note: for a function-style cast, remove the redundant '::pair'
a.cc:62:64: error: cannot call constructor 'std::pair<int, int>::pair' directly [-fpermissive]
   62 |                         nextlist.push_back(pair<int, int>::pair(pos.first + 1, pos.second));
      |                                            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:62:64: note: for a function-style cast, remove the redundant '::pair'
a.cc: In function 'int main()':
a.cc:92:56: error: cannot call constructor 'std::pair<int, int>::pair' directly [-fpermissive]
   92 |                 nextlist.push_back(pair<int, int>::pair(0, 0));
      |                                    ~~~~~~~~~~~~~~~~~~~~^~~~~~
a.cc:92:56: note: for a function-style cast, remove the redundant '::pair'