Language: C++

// atcoder/acl1/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>
#include <atcoder/mincostflow>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;
using namespace atcoder;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  const int inf = 1 << 29;

  int h, w;
  while (cin >> h >> w) {
    const int H = 50 + 2;
    const int W = 50 + 2;
    static char g[H][W];
    static int idx[H][W];
    int cnt = 0;
    vec<int> src;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
        idx[i][j] = cnt++;
        if (g[i][j] == 'o') src.push_back(idx[i][j]);
      }
    }

    const int super_src = cnt++;
    const int snk = cnt++;

    mcf_graph<int, int> matching(cnt);
    each (i, src) {
      matching.add_edge(super_src, i, 1, 0);
    }

    static int cost[H][W];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (g[i][j] != 'o') continue;
        fill(&cost[0][0], &cost[H - 1][W - 1] + 1, inf);
        cost[i][j] = 0;
        queue<pair<int, int>> q;
        for (q.push({i, j}); q.size(); q.pop()) {
          pair<int, int> curr = q.front();
          if (curr != make_pair(i, j)) {
            matching.add_edge(idx[i][j], idx[curr.first][curr.second], 1, -cost[curr.first][curr.second]);
          }

          if (curr.first + 1 < h && g[curr.first + 1][curr.second] != '#') {
            auto& z = cost[curr.first + 1][curr.second];
            if (z == inf) {
              z = cost[curr.first][curr.second] + 1;
              q.push({curr.first + 1, curr.second});
            }
          }
          if (curr.second + 1 < w && g[curr.first][curr.second + 1] != '#') {
            auto& z = cost[curr.first][curr.second + 1];
            if (z == inf) {
              z = cost[curr.first][curr.second] + 1;
              q.push({curr.first, curr.second + 1});
            }
          }
        }
      }
    }

    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (g[i][j] != '#') {
          matching.add_edge(idx[i][j], snk, 1, 0);
        }
      }
    }

    auto p = matching.flow(super_src, snk);
    // cout << p << endl;
    cout << abs(p.second) << endl;
    // each (e, matching.edges()) {
    //   if (e.flow) cout << e.from << " -> " << e.to << ' ' << make_pair(e.cap, e.cost) << ", "  << e.flow << endl;
    // }
    // for (int i = 0; i < h; ++i) {
    //   for (int j = 0; j < w; ++j) {
    //     printf("%3d", idx[i][j]);
    //   }
    //   puts("");
    // }
    // break;
  }


  return 0;
}


Compiler output:
a.cc:6:10: fatal error: atcoder/mincostflow: No such file or directory
    6 | #include <atcoder/mincostflow>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.