Language: C++

#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf=1050000000;
const int maxn=217;
const int maxm=20500;
char c;
int n,m,s,t,u,v,w,h,y,edge_cnt=1;
int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn];
queue <int> q;
void addedge(int u,int v,int w) {
	++edge_cnt;
	next[edge_cnt]=first[u];
	first[u]=edge_cnt;
	to[edge_cnt]=v; 
	r[edge_cnt]=w;
	
	++edge_cnt;
	next[edge_cnt]=first[v];
	first[v]=edge_cnt;
	to[edge_cnt]=u;
	r[edge_cnt]=w;
}
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=to[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=to[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);
	scanf("%d%d",&h,&y); 
	n=h+y;
	s=n+1,t=n+2;
	for (int i=1; i<=h; i++)
		for (int j=1; j<=y; j++) {
			cin>>c;
			if (c=='S') addedge(s,i,inf),addedge(s,h+j,inf);
			if (c=='T') addedge(i,t,inf),addedge(h+j,t,inf);
			if (c=='o') addedge(i,h+j,1);
		}
	int ans=0;
	while (bfs()) {
		for (int i=1; i<=t; i++) cur[i]=first[i];
		ans+=dfs(s,inf);
	} 
	if (ans>=inf) ans=-1;
	printf("%d\n",ans);
	return 0;
}


Compiler output:
a.cc: In function 'void addedge(int, 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/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:2:
/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:11:27: note:                 'int next [20500]'
   11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn];
      |                           ^~~~
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:11:27: note:                 'int next [20500]'
   11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn];
      |                           ^~~~
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:11:27: note:                 'int next [20500]'
   11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn];
      |                           ^~~~
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:11:27: note:                 'int next [20500]'
   11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn];
      |                           ^~~~