Language: C++

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

//ford-fulkerson

//辺を表す構造体(行先,容量,逆辺(の番号))
struct edge{ll to,cap,rev;};

ll H,W;

class FordFulkerson{
public:
    V<V<edge>> G;//グラフの隣接リスト
    V<bool> used;//DFSですでに調べたかのフラグ

    explicit FordFulkerson(ll max_V){
        G.resize(max_V);
        used.resize(max_V);
    }

    //fromからtoへ容量capの辺をグラフに追加
    void add_edge(ll from,ll to,ll cap){
        G[from].push_back((edge){to,cap,(ll)G[to].size()});
        G[to].push_back((edge){from,0LL,(ll)G[from].size()-1});
    }

    //増加パスをDFSで探す
    ll dfs(ll v,ll t,ll f){
        if(v==t) return f;
        used[v]=1;
        for(int i=0;i<(int)G[v].size();i++){
            edge &e=G[v][i];
            if(!used[e.to]&&e.cap>0){
                ll 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;
    }

    //sからtへの最大流を求める
    ll max_flow(ll s,ll t){
        ll flow=0;
        while(true){
            rep(i,(ll)used.size()) used[i]=0;
            ll f=dfs(s,t,INF);
            if(f==0) return flow;
            flow+=f;
        }
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>H>>W;
    char a[H][W];
    P S,T;
    rep(i,H) rep(j,W){
        cin>>a[i][j];
        if(a[i][j]=='S') S=make_pair(i,j);
        if(a[i][j]=='T') T=make_pair(i,j);
    }
    FordFulkerson ff(H+W+2);
    rep(i,H){
        rep(j,W){
            if(a[i][j]=='S'){
                ff.add_edge(0,i+1,INF);
                ff.add_edge(0,H+j+1,INF);
            }else if(a[i][j]=='T'){
                ff.add_edge(i+1,H+W+1,INF);
                ff.add_edge(H+j+1,H+W+1,INF);
            }else if(a[i][j]=='o'){
                ff.add_edge(i+1,H+j+1,1LL);
                ff.add_edge(H+j+1,i+1,1LL);
            }
        }
    }
    ll ans=ff.max_flow(0,H+W+1);
    if(S/W==T/W||S%W==T%W) ans=-1;
    out(ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:113:9: error: no match for 'operator/' (operand types are 'P' {aka 'std::pair<long long int, long long int>'} and 'll' {aka 'long long int'})
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |        ~^~
      |        | |
      |        | ll {aka long long int}
      |        P {aka std::pair<long long int, long long int>}
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:2:
/usr/include/c++/14/complex:430:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const complex<_Tp>&)'
  430 |     operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:430:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/complex:439:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const _Tp&)'
  439 |     operator/(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:439:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/complex:448:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const _Tp&, const complex<_Tp>&)'
  448 |     operator/(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:448:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   mismatched types 'const std::complex<_Tp>' and 'll' {aka 'long long int'}
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'll' {aka 'long long int'}
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'll' {aka 'long long int'}
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/valarray:1199:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__divides, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__divides, _Tp>::result_type> std::operator/(const valarray<_Tp>&, const valarray<_Tp>&)'
 1199 | _DEFINE_BINARY_OPERATOR(/, __divides)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1199:1: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::valarray<_Tp>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/valarray:1199:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__divides, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__divides, _Tp>::result_type> std::operator/(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1199 | _DEFINE_BINARY_OPERATOR(/, __divides)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1199:1: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::valarray<_Tp>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
/usr/include/c++/14/valarray:1199:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__divides, _Tp>::result_type> std::operator/(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1199 | _DEFINE_BINARY_OPERATOR(/, __divides)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1199:1: note:   template argument deduction/substitution failed:
a.cc:113:10: note:   mismatched types 'const std::valarray<_Tp>' and 'll' {aka 'long long int'}
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |          ^
a.cc:113:14: error: no match for 'operator/' (operand types are 'P' {aka 'std::pair<long long int, long long int>'} and 'll' {aka 'long long int'})
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |             ~^~
      |             | |
      |             | ll {aka long long int}
      |             P {aka std::pair<long long int, long long int>}
/usr/include/c++/14/complex:430:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const complex<_Tp>&)'
  430 |     operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:430:5: note:   template argument deduction/substitution failed:
a.cc:113:15: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |               ^
/usr/include/c++/14/complex:439:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const _Tp&)'
  439 |     operator/(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:439:5: note:   template argument deduction/substitution failed:
a.cc:113:15: note:   'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |               ^
/usr/include/c++/14/complex:448:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const _Tp&, const complex<_Tp>&)'
  448 |     operator/(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:448:5: note:   template argument deduction/substitution failed:
a.cc:113:15: note:   mismatched types 'const std::complex<_Tp>' and 'll' {aka 'long long int'}
  113 |     if(S/W==T/W||S%W==T%W) ans=-1;
      |               ^
/usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_typ