Language: C++

#include <bits/stdc++.h>
using namespace std;

const int N = 0;

pair < int , int > start;
pair < int , int > end;
int vis[2017][2017];
int dr[4] = { 1 , 0 , -1 , 0 };
int dc[4] = { 0 , 1 , 0 , -1 };
int flag = 0;
string one,two,three,four;

int bfs()
{
	queue < pair < pair < int , int > , string > > q;
	q.push(make_pair(start,""));
	while(!q.empty())
	{
		pair < pair < int , int > , string > u = q.front();
		q.pop();
		if(u.first==end)
		{
			if(flag==0)
			{
				one = u.second;
				flag++;
				return 0;
			}
			if(flag==1)
			{
				two = u.second;
				flag++;
				return 0;
			}
			if(flag==2)
			{
				three = u.second;
				flag++;
				return 0;
			}
			if(flag==3)
			{
				four = u.second;
				return 0;
			}
		}
		if(u.first!=start && u.first!=end)
		{
			vis[u.first.first][u.first.second] = 1;
		}
		for(int i=0;i<4;i++)
		{
			if(u.first.first + dc[i] >=0 && u.first.first + dc[i] <= 2000 && u.first.second + dr[i] >=0 && u.first.second + dr[i] <=2000 && vis[u.first.first + dc[i]][u.first.second + dr[i]]==0)
			{
			if(i==0)
				q.push(make_pair(make_pair(u.first.first + dc[i] , u.first.second + dr[i]) , u.second + "U"));
			if(i==1)
				q.push(make_pair(make_pair(u.first.first + dc[i] , u.first.second + dr[i]) , u.second + "R"));
			if(i==2)
				q.push(make_pair(make_pair(u.first.first + dc[i] , u.first.second + dr[i]) , u.second + "D"));
			if(i==3)
				q.push(make_pair(make_pair(u.first.first + dc[i] , u.first.second + dr[i]) , u.second + "L"));
			}
		}
	} 
}


int main()
{
	int x,y;
	cin >> x >> y;
	x+=1000; y+=1000;
	start = make_pair(x,y);
	cin >> x >> y;
	x+=1000; y+=1000;
	end = make_pair(x,y);
	bfs();
	memset(vis,0,sizeof(vis));
	pair < int , int > now = start;
	for(int i=0;i<one.size();i++)
	{
		if(now!= start && now!=end) vis[now.first][now.second]++;
		if(one[i]=='U') now.second++;
		if(one[i]=='D') now.second--;
		if(one[i]=='L') now.first--;
		if(one[i]=='R') now.first++;
	}
	bfs();
	memset(vis,0,sizeof(vis));
	now = start;
	for(int i=0;i<two.size();i++)
	{
		if(now!= start && now!=end) vis[now.first][now.second]++;
		if(two[i]=='U') now.second++;
		if(two[i]=='D') now.second--;
		if(two[i]=='L') now.first--;
		if(two[i]=='R') now.first++;
	}
	now = start;
	for(int i=0;i<one.size();i++)
	{
		if(now!= start && now!=end) vis[now.first][now.second]++;
		if(one[i]=='U') now.second++;
		if(one[i]=='D') now.second--;
		if(one[i]=='L') now.first--;
		if(one[i]=='R') now.first++;
	}
	bfs();
	memset(vis,0,sizeof(vis));
	now = start;
	for(int i=0;i<one.size();i++)
	{
		if(now!= start && now!=end) vis[now.first][now.second]++;
		if(three[i]=='U') now.second++;
		if(three[i]=='D') now.second--;
		if(three[i]=='L') now.first--;
		if(three[i]=='R') now.first++;
	}
	now = start;
	for(int i=0;i<two.size();i++)
	{
		if(now!= start && now!=end) vis[now.first][now.second]++;
		if(two[i]=='U') now.second++;
		if(two[i]=='D') now.second--;
		if(two[i]=='L') now.first--;
		if(two[i]=='R') now.first++;
	}
	now = start;
	for(int i=0;i<one.size();i++)
	{
		if(now!= start && now!=end) vis[now.first][now.second]++;
		if(one[i]=='U') now.second++;
		if(one[i]=='D') now.second--;
		if(one[i]=='L') now.first--;
		if(one[i]=='R') now.first++;
	}
	bfs();
	reverse(two.begin(),two.end());
	reverse(four.begin(),four.end());

	for(int i=0;i<two.size();i++)
	{
		if(two[i]=='U') two[i] = 'D';
		else if(two[i]=='D') two[i] = 'U';
		else if(two[i]=='R') two[i] = 'L';
		else if(two[i]=='L') two[i] = 'R';
	}
	
	for(int i=0;i<four.size();i++)
	{
		if(four[i]=='U') four[i] = 'D';
		else if(four[i]=='D') four[i] = 'U';
		else if(four[i]=='R') four[i] = 'L';
		else if(four[i]=='L') four[i] = 'R';
	}

	cout << one << two << three << four;
}

Compiler output:
a.cc: In function 'int bfs()':
a.cc:22:29: error: reference to 'end' is ambiguous
   22 |                 if(u.first==end)
      |                             ^~~
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:7:20: note:                 'std::pair<int, int> end'
    7 | pair < int , int > end;
      |                    ^~~
a.cc:48:47: error: reference to 'end' is ambiguous
   48 |                 if(u.first!=start && u.first!=end)
      |                                               ^~~
/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:7:20: note:                 'std::pair<int, int> end'
    7 | pair < int , int > end;
      |                    ^~~
a.cc: In function 'int main()':
a.cc:78:9: error: reference to 'end' is ambiguous
   78 |         end = make_pair(x,y);
      |         ^~~
/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:7:20: note:                 'std::pair<int, int> end'
    7 | pair < int , int > end;
      |                    ^~~
a.cc:84:40: error: reference to 'end' is ambiguous
   84 |                 if(now!= start && now!=end) vis[now.first][now.second]++;
      |                                        ^~~
/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:7:20: note:                 'std::pair<int, int> end'
    7 | pair < int , int > end;
      |                    ^~~
a.cc:95:40: error: reference to 'end' is ambiguous
   95 |                 if(now!= start && now!=end) vis[now.first][now.second]++;
      |                                        ^~~
/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:7:20: note:                 'std::pair<int, int> end'
    7 | pair < int , int > end;
      |                    ^~~
a.cc:104:40: error: reference to 'end' is ambiguous
  104 |                 if(now!= start && now!=end) vis[now.first][now.second]++;
      |                                        ^~~
/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:7:20: note:                 'std::pair<int, int> end'
    7 | pair < int , int > end;
      |                    ^~~
a.cc:115:40: error: reference to 'end' is ambiguous
  115 |                 if(now!= start && now!=end) vis[now.first][now.second]++;
      |                                        ^~~
/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
      |     ^