Language: C++

#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int inf=1050000000;
int h,w,s,t,edge_cnt=1,xs,xt,ys,yt;
char c[110][110];
int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010];
int num(int x,int y){
	return (x-1) * h + y;
}
queue <int> q;
void addedge(int u,int v) {
	++edge_cnt;
	next[edge_cnt]=first[u];
	first[u]=edge_cnt;
	too[edge_cnt]=v; 
	r[edge_cnt]=1;
	
	++edge_cnt;
	next[edge_cnt]=first[v];
	first[v]=edge_cnt;
	too[edge_cnt]=u;
	r[edge_cnt]=1;
}
bool bfs(){
	q.push(s);
	fill(d+1,d+t+1,0);
	d[s]=1;
	while (!q.empty()) {
		int u=q.front();
		q.pop();
		for (int e=first[u]; e; e=next[e]) {
			int v=too[e];
			if (d[v]==0 && r[e]>0) d[v]=d[u]+1,q.push(v);
		}
	}
	return d[t]>0;
}
int dfs(int x,int budget){
	if (x==t) return budget;
	int ans=0;
	for (int &e=cur[x]; e; e=next[e]) {
		int v=too[e];
		if (d[v]==d[x]+1 && r[e]>0) {
			int ret=dfs(v,min(budget,r[e]));
			ans    += ret;
			r[e]   -= ret;
			r[e^1] += ret;
			budget -= ret;
			if (budget==0) break;
		}
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>h>>w;
	for (int i=1; i<=h; i++) 
		for (int j=1; j<=w; j++) {
			cin>>c[i][j];
			if (c[i][j]=='S') s=num(i,j),xs=i,ys=j,c[i][j]='o';
			if (c[i][j]=='T') t=num(i,j),xt=i,yt=j,c[i][j]='o';	
		}
	for (int i=1; i<=h; i++) 
		for (int j=1; j<=w; j++)if (c[i][j]=='o'){ 
			for (int u=j; u<=w; u++) if (u!=j && c[i][u]=='o') addedge(num(i,j),num(i,u));
			for (int u=i; u<=h; u++) if (u!=i && c[u][j]=='o') addedge(num(i,j),num(u,j));
		}
	n=h*w;
	while (bfs()) {
		for (int i=1; i<=n; i++) cur[i]=first[i];
		ans+=dfs(s,inf);
	} 
	if (xs==xt || ys==yt) ans=-1;
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'void addedge(int, int)':
a.cc:15:9: error: reference to 'next' is ambiguous
   15 |         next[edge_cnt]=first[u];
      |         ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:8:44: note:                 'int next [2000010]'
    8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010];
      |                                            ^~~~
a.cc:21:9: error: reference to 'next' is ambiguous
   21 |         next[edge_cnt]=first[v];
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:8:44: note:                 'int next [2000010]'
    8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010];
      |                                            ^~~~
a.cc: In function 'bool bfs()':
a.cc:33:43: error: reference to 'next' is ambiguous
   33 |                 for (int e=first[u]; e; e=next[e]) {
      |                                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:8:44: note:                 'int next [2000010]'
    8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010];
      |                                            ^~~~
a.cc: In function 'int dfs(int, int)':
a.cc:43:34: error: reference to 'next' is ambiguous
   43 |         for (int &e=cur[x]; e; e=next[e]) {
      |                                  ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:8:44: note:                 'int next [2000010]'
    8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010];
      |                                            ^~~~