Language: C++

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef pair<int, int> pint;

int H, W;
struct Edge { int num, to; Edge(int n, int t) : num(n), to(t) {}};
vector<vector<Edge>> edges;
bool bfs(int broken_edge, vector<int>& dist) {
    dist[(H - 1) * W + W - 1] = 0;
    queue<int> que; que.push((H - 1) * W + W - 1);
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(const Edge& e : edges[cur]) {
            if(e.num == broken_edge || dist[e.to] != INF) continue;
            dist[e.to] = dist[cur] + 1;
            que.push(e.to);
        }
    }
    return dist[0] == INF;
}

int solve(const vector<vector<int>>& wdist) {
    vector<int> dist(H * W, INF);
    priority_queue<pint, vector<pint>, greater<pint>> que;
    dist[(H - 1) * W + W - 1] = 0; que.emplace(0, (H - 1) * W + W - 1);
    auto upd = [](int& a, int b) { return a > b ? (a = b, true) : false;};
    while(!que.empty()) {
        int cos, node;
        tie(cos, node) = que.top(); que.pop();
        if(dist[node] < cos) continue;
        for(const Edge& e : edges[node]) {
            int ncos = max(cos + 1, wdist[e.num][e.to]);
            if(upd(dist[e.to], ncos)) que.emplace(ncos, e.to);
        }
    }
    return dist[0];
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while(cin >> H >> W && H) {
        int t_, edgenum = 0;
        edges.assign(H * W);
        rep(i, H) {
            rep(j, W - 1) {
                cin >> t_;
                if(t_ == 0) {
                    edges[i * W + j].emplace_back(edgenum, i * W + j + 1);
                    edges[i * W + j + 1].emplace_back(edgenum, i * W + j);
                    ++edgenum;
                }
            }
            if(i == H - 1) continue;
            rep(j, W) {
                cin >> t_;
                if(t_ == 0) {
                    edges[i * W + j].emplace_back(edgenum, (i + 1) * W + j);
                    edges[(i + 1) * W + j].emplace_back(edgenum, i * W + j);
                    ++edgenum;
                }
            }
        }
        vector<vector<int>> wdist(edgenum, vector<int>(H * W, INF));
        rep(i, edgenum) if(bfs(i, wdist[i])) goto fail;
        cout << solve(wdist) << endl;
        continue;
      fail:
        cout << "-1" << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:21: error: no matching function for call to 'std::vector<std::vector<Edge> >::assign(int)'
   45 |         edges.assign(H * W);
      |         ~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<Edge>; _Alloc = std::allocator<std::vector<Edge> >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:828:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<Edge>; _Alloc = std::allocator<std::vector<Edge> >; size_type = long unsigned int; value_type = std::vector<Edge>]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<Edge>; _Alloc = std::allocator<std::vector<Edge> >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:855:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<Edge> >'
  855 |       assign(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~