Language: C++

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

struct edge {
    int from, to;
    ll cost;
};

class Dijkstra {
    int V;
    vector<vector<edge>> edges;
    vector<ll> dist;
    vector<ll> prev;
    vector<ll> route_cnt;

public:
    Dijkstra(int v) : V(v) {
        edges.resize(V);
        dist.resize(V, INF);
        prev.resize(V, INF);
        route_cnt.resize(V, 0);
    }

    void add_edge(int from, int to, ll cost) {
        edges[from].push_back({from, to, cost});
    }

    /**
     * @param goal 0-indexed
     * @return return cost to reach the goal. return INF if the goal is unreachable.
     */
    ll get_cost(int goal) {
        return dist[goal];
    }

    ll get_route_cnt(ll goal) {
        print(route_cnt);
        return route_cnt[goal];
    }

    void exec(int start) {
        dist[start] = 0;
        route_cnt[start] = 1;
        priority_queue<P, vector<P>, greater<>> queue;
        queue.push({dist[start], start});
        while (!queue.empty()) {
            P p = queue.top();
            queue.pop();
            ll prev_cost = p.first;
            ll src = p.second;
            if (dist[src] < prev_cost) continue;

            for (edge &e : edges[src]) {
                ll to = e.to;
                ll cost = e.cost;
                if (cost != INF && dist[to] > dist[src] + cost) {
                    dist[to] = dist[src] + cost;
                    queue.push({dist[to], to});
                    prev[to] = src;
                }
                if (dist[to] == dist[src] + cost) {
                    route_cnt[to] += route_cnt[src];
                }
            }
        }
    }
};

void Main() {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    rep(i, H) cin >> grid[i];
    Dijkstra dijkstra(H * W+1000);
    ll cnt = 0;
    rep(i, H) {
        rep(j, W) {
            if (grid[i][j] == '#') continue;
            else cnt++;
            rep(d, 4) {
                int x = dx[d];
                int y = dy[d];
                if (0 <= i + y && i + y <= H - 1 && 0 <= j + x && j + x <= W - 1 && grid[i + y][j + x] != '#') {
                    dijkstra.add_edge(i * W + j, (i + y) * W + (j + x), 1);
                }
            }
        }
    }
    dijkstra.exec(0);
    ll ans = dijkstra.get_cost(H * W - 1);
    if (ans == INF) {
        cout << -1 << '\n';
    } else {
        cout << cnt - (ans + 1) << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Compiler output:
a.cc: In member function 'll Dijkstra::get_route_cnt(ll)':
a.cc:60:9: error: 'print' was not declared in this scope; did you mean 'rint'?
   60 |         print(route_cnt);
      |         ^~~~~
      |         rint