Language: C++

#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int N=2010; 
const int offset=1000;
typedef pair<int,int> PII;
int sx, sy, tx, ty;
int g[N][N];//0-路，1-墙
int dist[N][N]; 
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
PII prev[N][N];
void bfs(int sx, int sy, int tx, int ty){
	memset(prev,0,sizeof(prev));
	
	queue<PII> q;
	memset(dist, -1, sizeof(dist));
	
	q.push({sx,sy});
	dist[sx][sy]=0;
	
	while(q.size()){
		PII t=q.front();q.pop();
		int x=t.first, y=t.second;
		if(x==tx && y==ty){
			PII k=make_pair(tx,ty);
//			printf("(%d,%d)->",tx-offset,ty-offset);
			k=prev[tx][ty];
			int p=tx,q=ty; 
			int a,b;
			while(true){
				a=k.first, b=k.second;
				if(a==sx && b==sy) break;
				g[a][b]=1;
				if(a==p && b<q) cout<<'D';
				else if(a==p && b>q) cout<<'U';
				else if(a<p && b==q) cout<<'L';
				else if(a>p && b==q) cout<<'R';
//				printf("(%d,%d)->",a-offset,b-offset);
				k=prev[a][b];
				p=a,q=b;
			}
			a=sx,b=sy;
			if(a==p && b<q) cout<<'D';
			else if(a==p && b>q) cout<<'U';
			else if(a<p && b==q) cout<<'L';
			else if(a>p && b==q) cout<<'R';
			
			break;
		}
		
		for(int i=0;i<4;i++){
			int a=dx[i]+x,b=dy[i]+y;
			if(dist[a][b]==-1 && g[a][b]!=1){
				dist[a][b]=dist[x][y]+1;
				prev[a][b]={x,y};
				q.push({a,b});
			}
		}
	}
}
int main(){
	
	cin>>sx>>sy>>tx>>ty;
	
	sx+=offset, sy+=offset, tx+=offset,ty+=offset;//to be positive
	
	bfs(tx, ty, sx, sy);
	
	bfs(sx, sy, tx, ty);
	
	bfs(tx, ty, sx, sy);

	bfs(sx, sy, tx, ty);

	
	return 0;
}


Compiler output:
a.cc: In function 'void bfs(int, int, int, int)':
a.cc:14:16: error: reference to 'prev' is ambiguous
   14 |         memset(prev,0,sizeof(prev));
      |                ^~~~
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:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:5: note:                 'PII prev [2010][2010]'
   12 | PII prev[N][N];
      |     ^~~~
a.cc:14:30: error: reference to 'prev' is ambiguous
   14 |         memset(prev,0,sizeof(prev));
      |                              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:5: note:                 'PII prev [2010][2010]'
   12 | PII prev[N][N];
      |     ^~~~
a.cc:28:27: error: reference to 'prev' is ambiguous
   28 |                         k=prev[tx][ty];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:5: note:                 'PII prev [2010][2010]'
   12 | PII prev[N][N];
      |     ^~~~
a.cc:40:35: error: reference to 'prev' is ambiguous
   40 |                                 k=prev[a][b];
      |                                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:5: note:                 'PII prev [2010][2010]'
   12 | PII prev[N][N];
      |     ^~~~
a.cc:56:33: error: reference to 'prev' is ambiguous
   56 |                                 prev[a][b]={x,y};
      |                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:5: note:                 'PII prev [2010][2010]'
   12 | PII prev[N][N];
      |     ^~~~