Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
using namespace std;
using P = pair<int, int>;
const int maplen = 2020;
const int offset = 1010;

string ans = "";
vector<vector<bool>> isvisit(maplen, vector<bool>(maplen, false));

void search(int sx, int sy, int tx, int ty){
    isvisit[sx+offset][sy+offset] = false;
    isvisit[tx+offset][ty+offset] = false;
    vector<vector<bool>> isvisit_1(maplen, vector<bool>(maplen, false));
    vector<vector<P>> past(maplen, vector<P>(maplen));

    for(int i = 0; i < maplen; i++){
        for(int j = 0; j < maplen; j++) isvisit_1[i][j] = isvisit[i][j];
    }
    queue<P> Q1;
    Q1.push(make_pair(sx+offset, sy+offset));
    while(!Q1.empty() && !isvisit_1[tx+offset][ty+offset]){
        int curx, cury;
        curx = Q1.front().first;
        cury = Q1.front().second;
        Q1.pop();

        if(cury+1 < maplen && !isvisit_1[curx][cury+1]){
            past[curx][cury+1] = make_pair(curx, cury);
            isvisit_1[curx][cury+1] = true;
            Q1.push(make_pair(curx, cury+1));
        }

        if(cury-1 >= 0 && !isvisit_1[curx][cury-1]){
            past[curx][cury-1] = make_pair(curx, cury);
            isvisit_1[curx][cury-1] = true;
            Q1.push(make_pair(curx, cury-1));
        }

        if(curx+1 < maplen && !isvisit_1[curx+1][cury]){
            past[curx+1][cury] = make_pair(curx, cury);
            isvisit_1[curx+1][cury] = true;
            Q1.push(make_pair(curx+1, cury));
        }

        if(curx-1 >= 0 && !isvisit_1[curx-1][cury]){
            past[curx-1][cury] = make_pair(curx, cury);
            isvisit_1[curx-1][cury] = true;
            Q1.push(make_pair(curx-1, cury));
        }
    }
    stack<char> coans;
    P cur = make_pair(tx+offset, ty+offset);
    while(cur != make_pair(sx+offset, sy+offset)){
        int curx = cur.first;
        int cury = cur.second;
        int pastx = past[curx][cury].first;
        int pasty = past[curx][cury].second;
        isvisit[pastx][pasty] = true;
        if(curx == pastx){
            if(cury > pasty){
                coans.push('U');
            }else{
                coans.push('D');
            }
        }else{
            if(curx > pastx){
                coans.push('R');
            }else{
                coans.push('L');
            }
        }

        cur = make_pair(pastx, pasty);
    }
    while(!coans.empty()){
        ans += coans.top();
        coans.pop();
    }

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    search(sx, sy, tx, ty);
    search(tx, ty, sx, sy);
    search(sx, sy, tx, ty);
    search(tx, ty, sx, sy);
    
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void search(int, int, int, int)':
a.cc:84:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   84 | int main(){
      |         ^~
a.cc:84:9: note: remove parentheses to default-initialize a variable
   84 | int main(){
      |         ^~
      |         --
a.cc:84:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:84:11: error: a function-definition is not allowed here before '{' token
   84 | int main(){
      |           ^
a.cc:95:2: error: expected '}' at end of input
   95 | }
      |  ^
a.cc:14:44: note: to match this '{'
   14 | void search(int sx, int sy, int tx, int ty){
      |                                            ^