Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+5;
const int maxm=4e4+5;
const int inf=1e9;


int k,l,p,q,maxx;
struct edge
{
	int fr,to,nxt;
	int c,f;
}graph[maxm];
int head[maxn];
int tot;
int level[maxn];
int n,m;
int s,t;
string str;
struct node
{
	int x,y,id;
}a[maxn],start,end;


bool cmp(node a,node b)
{
	return a.y<b.y;
}
bool dinic_bfs()
{
	memset(level,0,sizeof(level));
	queue<int> que;
	que.push(s);
	level[s] = 1;
	while (!que.empty())
	{
		int u = que.front(); que.pop();
		for (int i = head[u]; i != -1; i = graph[i].nxt)
		{
			int v = graph[i].to;
			if (!level[v] && graph[i].c > graph[i].f)
			{
				level[v] = level[u] + 1;
				que.push(v);
			}
		}
	}
	return level[t] != 0;
}

int dinic_dfs(int u, int cpflow)
{
	if (u == t) return cpflow;
	int addflow = 0;
	for (int i = head[u]; i != -1 && addflow < cpflow; i = graph[i].nxt)
	{
		int v = graph[i].to;
		if (level[u] + 1 == level[v] && graph[i].c > graph[i].f)
		{
			int tmpadd = dinic_dfs(v, min(cpflow - addflow, graph[i].c - graph[i].f));
			graph[i].f += tmpadd;
			graph[i ^ 1].f -= tmpadd;
			addflow += tmpadd;
		}
	}
	return addflow;
}

int dinic()
{
	int maxflow = 0;
	while (dinic_bfs())
		maxflow += dinic_dfs(s, inf);
	return maxflow;
}

void addEdge(int u,int v,int c, int i)
{
	graph[tot].to = v;
	graph[tot].fr = u;
	graph[tot].nxt = head[u];
	graph[tot].c = c;
	graph[tot].f = 0;
	head[u] = tot++;
	graph[tot].to = u;
	graph[tot].fr = v;
	graph[tot].nxt = head[v];
	graph[tot].c = 0;
	graph[tot].f = 0;
	head[v] = tot++;
}

void init()
{
	for(int i=1;i<maxn;i++)
		head[i]=-1;
	tot=0;
}

int main()
{
	int cnt=0;
    init();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
    	cin>>str;
	   	for(int j=0;j<m;j++)
    	{
    		if(str[j]!='.')
    		{
    			cnt++;
    			a[cnt].x=i,a[cnt].y=j+1,a[cnt].id=cnt;
    			if(str[j]=='S')
				{
					s=cnt;
					start.x=a[cnt].x,start.y=a[cnt].y,start.id=a[cnt].id;
				} 
    			if(str[j]=='T')
    			{
    				t=cnt;
					end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id;
				}
			}
		}
	}
	for(int i=1;i<cnt;i++)
	{
		if(a[i].x==a[i+1].x)
		{
			addEdge(a[i].id,a[i+1].id,1,0);
			addEdge(a[i+1].id,a[i].id,1,0);
		}
	}
	sort(a+1,a+1+cnt,cmp);
	for(int i=1;i<cnt;i++)
	{
		if(a[i].y==a[i+1].y)
		{
			addEdge(a[i].id,a[i+1].id,1,0);
			addEdge(a[i+1].id,a[i].id,1,0);
		}
	}
	if(start.y==end.y||start.x==end.x)
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<dinic();
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:123:41: error: reference to 'end' is ambiguous
  123 |                                         end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id;
      |                                         ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:23:16: note:                 'node end'
   23 | }a[maxn],start,end;
      |                ^~~
a.cc:123:56: error: reference to 'end' is ambiguous
  123 |                                         end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id;
      |                                                        ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:23:16: note:                 'node end'
   23 | }a[maxn],start,end;
      |                ^~~
a.cc:123:71: error: reference to 'end' is ambiguous
  123 |                                         end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id;
      |                                                                       ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:23:16: note:                 'node end'
   23 | }a[maxn],start,end;
      |                ^~~
a.cc:145:21: error: reference to 'end' is ambiguous
  145 |         if(start.y==end.y||start.x==end.x)
      |                     ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:23:16: note:                 'node end'
   23 | }a[maxn],start,end;
      |                ^~~
a.cc:145:37: error: reference to 'end' is ambiguous
  145 |         if(start.y==end.y||start.x==end.x)
      |                                     ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:23:16: note:                 'node end'
   23 | }a[maxn],start,end;
      |                ^~~