Language: C++

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

struct Edge { int to, cap, rev; };

#define MAX_N 30000
class Dinic {
public:
  vector<Edge> G[MAX_N];
  int level[MAX_N], iter[MAX_N];

  void add_edge(int from, int to, int cap) {
    G[from].pb((Edge) { to, cap, (int)G[to].size() });
    G[to].pb((Edge) { from, 0, (int)G[from].size() - 1 });
  }

  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (Edge e : G[x]) {
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[x] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int x, int t, int f) {
    if (x == t) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      int f;
      while (true) {
        f = dfs(s, t, INF);
        if (f <= 0) break;
        flow += f;
      }
    }
  }
};

int W, H;
int SX, SY, TX, TY;
char A[100][100];

int WI[100], HI[100];
int IN[100][100], OUT[100][100];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W;
  rep(y, H) {
    rep(x, W) {
      cin >> A[x][y];
      if (A[x][y] == 'S') SX = x, SY = y;
      if (A[x][y] == 'T') TX = x, TY = y;
    }
  }
  rep(i, W) WI[i] = 2*W*H + i;
  rep(i, H) HI[i] = 2*W*H + W + i;
  rep(x, W) {
    rep(y, H) {
      IN[x][y] = 2*(x*H + y);
      OUT[x][y] = 2*(x*H + y)+1;
    }
  }

  Dinic dinic;
  rep(x, W) {
    rep(y, H) {
      if (A[x][y] == '.') continue;
      // (x,y) <-> WI[x]
      dinic.add_edge(OUT[x][y], WI[x], INF);
      dinic.add_edge(WI[x], IN[x][y], INF);
      // (x,y) <-> HI[x]
      dinic.add_edge(OUT[x][y], HI[y], INF);
      dinic.add_edge(HI[y], IN[x][y], INF);

      // in -> out
      dinic.add_edge(IN[x][y], OUT[x][y], 1);
    }
  }
  int ans = dinic.max_flow(OUT[SX][SY], IN[TX][TY]);
  if (ans == INF) cout << -1 << "\n";
  else cout << ans << "\n";
  return 0;
}


Compiler output:
a.cc: In member function 'void Dinic::bfs(int)':
a.cc:37:5: error: 'memset' was not declared in this scope
   37 |     memset(level, -1, sizeof(level));
      |     ^~~~~~
a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   10 | #include <iomanip>
  +++ |+#include <cstring>
   11 | using namespace std;
a.cc: In member function 'int Dinic::max_flow(int, int)':
a.cc:73:7: error: 'memset' was not declared in this scope
   73 |       memset(iter, 0, sizeof(iter));
      |       ^~~~~~
a.cc:73:7: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'