Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
char map[111][111];
struct edge
{
	int to;
	int res;
	int next;
}e[33333];
int pe=222;
void insert(int a,int to,int cap)
{
	e[pe]=(edge){to,cap,e[a].next};
	e[a].next=pe++;
}
void addedge(int a,int to,int cap)
{
	insert(a,to,cap);
	insert(to,a,0);
}
int s,t;
int d[3333];
int q[3333],hq,tq;
int vis[3333],pv;
int cur[3333];
bool bfs()
{
	for(q[hq=1]=t,tq=2,vis[t]=++pv,d[t]=0;hq!=tq;++hq)
		for(register int p=e[q[hq]].next;p;p=e[p].next)
			if(e[p^1].res&&vis[e[p].to]!=pv)
				vis[e[p].to]=pv,d[e[p].to]=d[q[hq]]+1,q[tq++]=e[p].to;
	return vis[s]==pv;
}
int dfs(int o,int min)
{
	if(o==t||min==0)return min;
	int f=0,tmp;
	for(register int p;cur[o];cur[o]=e[cur[o]].next)
	{
		p=cur[o];
		if(e[p].res&&d[e[p].to]==d[o]-1&&(tmp=dfs(e[p].to,dmin(min,e[p].res))))
		{
			f+=tmp;
			e[p].res-=tmp;
			e[p^1].res+=tmp;
			min-=tmp;
			if(min==0)return f;
		}
	}
	return f;
}
int dinic()
{
	int fl=0;
	while(bfs())
	{
		for(register int i=1;i<=t;++i)cur[i]=e[i].next;
		fl+=dfs(s,0x7fffffff);
	}
	return fl;
}
int main()
{
	int n=io::F(),m=io::F();
	for(register int i=1;i<=n;++i)gets(map[i]+1);
	s=n+m+1,t=n+m+2;
	int sx,sy,tx,ty;
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=m;++j)
		{
			if(map[i][j]=='o')addedge(i,j+n,1),addedge(j+n,i,1);
			if(map[i][j]=='S')sx=i,sy=j;
			if(map[i][j]=='T')tx=i,ty=j;
		}
	addedge(s,sx,100000);
	addedge(s,sy+n,100000);
	addedge(tx,t,100000);
	addedge(ty+n,t,100000);
	int tmp=dinic();
	if(tmp>=100000)puts("-1");
		else printf("%d\n",tmp);
	return 0;
}




Compiler output:
a.cc: In function 'bool bfs()':
a.cc:60:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   60 |                 for(register int p=e[q[hq]].next;p;p=e[p].next)
      |                                  ^
a.cc: In function 'int dfs(int, int)':
a.cc:69:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   69 |         for(register int p;cur[o];cur[o]=e[cur[o]].next)
      |                          ^
a.cc: In function 'int dinic()':
a.cc:88:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   88 |                 for(register int i=1;i<=t;++i)cur[i]=e[i].next;
      |                                  ^
a.cc: In function 'int main()':
a.cc:96:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   96 |         for(register int i=1;i<=n;++i)gets(map[i]+1);
      |                          ^
a.cc:96:39: error: 'gets' was not declared in this scope; did you mean 'getw'?
   96 |         for(register int i=1;i<=n;++i)gets(map[i]+1);
      |                                       ^~~~
      |                                       getw
a.cc:99:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   99 |         for(register int i=1;i<=n;++i)
      |                          ^
a.cc:100:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  100 |                 for(register int j=1;j<=m;++j)
      |                                  ^