Language: C++

#include <iostream>


#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n)                       _range(i, 0, n)
#define _range(i, a, b)                  for (int i = int(a); i < int(b); ++i)
#define rep(...)                         _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)

#define _rrep(i, n)      _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...)        _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)

template <class T> bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}


using ll = long long;
using namespace std;

using edge    = struct { int to, cap, cost, rev; };
using G       = vector<vector<edge>>;
const int inf = 1 << 29;

void add_edge(G &graph, int a, int b, int c, int d) {
    graph[a].push_back({b, c, d, int(graph[b].size())});
    graph[b].push_back({a, 0, -d, int(graph[a].size() - 1)});
}

int min_cost_flow(G &graph, int s, int t, int f) {
    using W = ll;
    W res   = 0;
    while (f) {
        int n = graph.size();
        int update;
        vector<W> dist(n, inf), pv(n, 0), pe(n, 0);
        dist[s] = 0;

        rep(loop, n) {
            update = false;
            rep(v, n) rep(i, graph[v].size()) {
                edge &e = graph[v][i];
                if (e.cap > 0 && chmin(dist[e.to], dist[v] + e.cost)) {
                    pv[e.to] = v, pe[e.to] = i;
                    update = true;
                }
            }
            if (!update) break;
        }

        if (dist[t] == inf) return -1;

        int d = f;
        for (int v = t; v != s; v = pv[v]) chmin(d, graph[pv[v]][pe[v]].cap);
        f -= d, res += d * dist[t];

        for (int v = t; v != s; v = pv[v]) {
            edge &e = graph[pv[v]][pe[v]];
            e.cap -= d;
            graph[v][e.rev].cap += d;
        }
    }
    return res;
}

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<string> s(n);
    rep(i, n) cin >> s[i];

    int counter = 0;
    int src, dst;
    vector<vector<int>> id(n, vector<int>(m, 0));


    rep(i, n) rep(j, m) {
        id[i][j] = counter++;
    }
    src = counter++;
    dst = counter++;


    G graph(counter);

    int number = 0;
    rep(i, n) rep(j, m) {
        if (s[i][j] == 'o') {
            number++;
            add_edge(graph, src, id[i][j], 1, 0);
        }

        if (s[i][j] != '#') { add_edge(graph, id[i][j], dst, 1, 0); }
    }

    rep(i, n) rep(j, m) {
        if (s[i][j] == '#') continue;

        if (i + 1 < n and s[i + 1][j] != '#') {
            add_edge(graph, id[i][j], id[i + 1][j], number, -1);
        }

        if (j + 1 < m and s[i][j + 1] != '#') {
            add_edge(graph, id[i][j], id[i][j + 1], number, -1);
        }
    }

    const auto ans = -min_cost_flow(graph, src, dst, number);

    // for (auto &edge: graph.edges()) {
    //     cerr << edge.from << " " << edge.to << " " << edge.cap << " "
    //          << edge.cost << " " << edge.flow << endl;
    // }

    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc:25:17: error: 'vector' does not name a type
   25 | using G       = vector<vector<edge>>;
      |                 ^~~~~~
a.cc:28:6: error: variable or field 'add_edge' declared void
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |      ^~~~~~~~
a.cc:28:15: error: 'G' was not declared in this scope
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |               ^
a.cc:28:18: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |                  ^~~~~
      |                  isgraph
a.cc:28:25: error: expected primary-expression before 'int'
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |                         ^~~
a.cc:28:32: error: expected primary-expression before 'int'
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |                                ^~~
a.cc:28:39: error: expected primary-expression before 'int'
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |                                       ^~~
a.cc:28:46: error: expected primary-expression before 'int'
   28 | void add_edge(G &graph, int a, int b, int c, int d) {
      |                                              ^~~
a.cc:33:19: error: 'G' was not declared in this scope
   33 | int min_cost_flow(G &graph, int s, int t, int f) {
      |                   ^
a.cc:33:22: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   33 | int min_cost_flow(G &graph, int s, int t, int f) {
      |                      ^~~~~
      |                      isgraph
a.cc:33:29: error: expected primary-expression before 'int'
   33 | int min_cost_flow(G &graph, int s, int t, int f) {
      |                             ^~~
a.cc:33:36: error: expected primary-expression before 'int'
   33 | int min_cost_flow(G &graph, int s, int t, int f) {
      |                                    ^~~
a.cc:33:43: error: expected primary-expression before 'int'
   33 | int min_cost_flow(G &graph, int s, int t, int f) {
      |                                           ^~~
a.cc:33:48: error: expression list treated as compound expression in initializer [-fpermissive]
   33 | int min_cost_flow(G &graph, int s, int t, int f) {
      |                                                ^
a.cc: In function 'int main()':
a.cc:73:5: error: 'vector' was not declared in this scope
   73 |     vector<string> s(n);
      |     ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | 
a.cc:73:18: error: expected primary-expression before '>' token
   73 |     vector<string> s(n);
      |                  ^
a.cc:73:20: error: 's' was not declared in this scope
   73 |     vector<string> s(n);
      |                    ^
a.cc:78:19: error: expected primary-expression before 'int'
   78 |     vector<vector<int>> id(n, vector<int>(m, 0));
      |                   ^~~
a.cc:82:9: error: 'id' was not declared in this scope; did you mean 'i'?
   82 |         id[i][j] = counter++;
      |         ^~
      |         i
a.cc:88:5: error: 'G' was not declared in this scope
   88 |     G graph(counter);
      |     ^
a.cc:94:22: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   94 |             add_edge(graph, src, id[i][j], 1, 0);
      |                      ^~~~~
      |                      isgraph
a.cc:94:34: error: 'id' was not declared in this scope; did you mean 'i'?
   94 |             add_edge(graph, src, id[i][j], 1, 0);
      |                                  ^~
      |                                  i
a.cc:94:13: error: 'add_edge' was not declared in this scope
   94 |             add_edge(graph, src, id[i][j], 1, 0);
      |             ^~~~~~~~
a.cc:97:40: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   97 |         if (s[i][j] != '#') { add_edge(graph, id[i][j], dst, 1, 0); }
      |                                        ^~~~~
      |                                        isgraph
a.cc:97:47: error: 'id' was not declared in this scope; did you mean 'i'?
   97 |         if (s[i][j] != '#') { add_edge(graph, id[i][j], dst, 1, 0); }
      |                                               ^~
      |                                               i
a.cc:97:31: error: 'add_edge' was not declared in this scope
   97 |         if (s[i][j] != '#') { add_edge(graph, id[i][j], dst, 1, 0); }
      |                               ^~~~~~~~
a.cc:104:22: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
  104 |             add_edge(graph, id[i][j], id[i + 1][j], number, -1);
      |                      ^~~~~
      |                      isgraph
a.cc:104:29: error: 'id' was not declared in this scope; did you mean 'i'?
  104 |             add_edge(graph, id[i][j], id[i + 1][j], number, -1);
      |                             ^~
      |                             i
a.cc:104:13: error: 'add_edge' was not declared in this scope
  104 |             add_edge(graph, id[i][j], id[i + 1][j], number, -1);
      |             ^~~~~~~~
a.cc:108:22: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
  108 |             add_edge(graph, id[i][j], id[i][j + 1], number, -1);
      |                      ^~~~~
      |                      isgraph
a.cc:108:29: error: 'id' was not declared in this scope; did you mean 'i'?
  108 |             add_edge(graph, id[i][j], id[i][j + 1], number, -1);
      |                             ^~
      |                             i
a.cc:108:13: error: 'add_edge' was not declared in this scope
  108 |             add_edge(graph, id[i][j], id[i][j + 1], number, -1);
      |             ^~~~~~~~
a.cc:112:37: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
  112 |     const auto ans = -min_cost_flow(graph, src, dst, number);
      |                                     ^~~~~
      |                                     isgraph
a.cc:112:36: error: 'min_cost_flow' cannot be used as a function
  112 |     const auto ans = -min_cost_flow(graph, src, dst, number);
      |                       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~