Language: C++

#include <unordered_set>
#include <iostream>
#include <algorithm>
#include <vector>

bool is_in_indices(int a, int b, std::unordered_set<std::string>* indices) {
  char key[6];
  sprintf(key, "%d_%d", a, b);
  return indices->count(std::string(key)) > 0;
}

void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
  if (cx == tx && cy == ty) {
    return;
  }
  if (cx < tx) {
    if (is_in_indices(cx + 1, cy, indices)) {
      result->push_back("R");
      return walk(cx + 1, tx, cy, ty, indices, result);
    }
  }
  if (cy < ty) {
    if (is_in_indices(cx, cy + 1, indices)) {
      result->push_back("D");
      return walk(cx, tx, cy + 1, ty, indices, result);
    }
  }
  if (cx > tx) {
    if (is_in_indices(cx - 1, cy, indices)) {
      result->push_back("L");
      return walk(cx - 1, tx, cy, ty, indices, result);
    }
  }
  if (cy > ty) {
    if (is_in_indices(cx cy - 1, indices)) {
      result->push_back("U");
      return walk(cx tx, cy - 1, ty, indices, result);
    }
  }

  if (is_in_indices(cx + 1, cy, indices)) {
    result->push_back("R");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
  if (is_in_indices(cx - 1, cy, indices)) {
    result->push_back("L");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
  if (is_in_indices(cx, cy + 1, indices)) {
    result->push_back("D");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
  if (is_in_indices(cx, cy - 1, indices)) {
    result->push_back("U");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
}

int main() {
  int sx = 0;
  int sy = 0;
  int tx = 0;
  int ty = 0;
  std::cin >> sx;
  std::cin >> sy;
  std::cin >> tx;
  std::cin >> ty;
  
  std::unordered_set<std::string> indices;
  std::vector<std::string> result;
  
  walk(sx, sy, tx, ty, &indices, &result);
  walk(tx, ty, sx, sy, &indices, &result);
  walk(sx, sy, tx, ty, &indices, &result);
  walk(tx, ty, sx, sy, &indices, &result);
  
  for (auto p&: result) {
    printf("%s", p.c_str());
  }
  printf("\n");
}

Compiler output:
a.cc: In function 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, std::vector<std::__cxx11::basic_string<char> >*)':
a.cc:35:25: error: expected ')' before 'cy'
   35 |     if (is_in_indices(cx cy - 1, indices)) {
      |                      ~  ^~~
      |                         )
a.cc:35:34: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   35 |     if (is_in_indices(cx cy - 1, indices)) {
      |                                  ^~~~~~~
      |                                  |
      |                                  std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:35:22: error: too few arguments to function 'bool is_in_indices(int, int, std::unordered_set<std::__cxx11::basic_string<char> >*)'
   35 |     if (is_in_indices(cx cy - 1, indices)) {
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:6:6: note: declared here
    6 | bool is_in_indices(int a, int b, std::unordered_set<std::string>* indices) {
      |      ^~~~~~~~~~~~~
a.cc:37:21: error: expected ')' before 'tx'
   37 |       return walk(cx tx, cy - 1, ty, indices, result);
      |                  ~  ^~~
      |                     )
a.cc:37:38: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   37 |       return walk(cx tx, cy - 1, ty, indices, result);
      |                                      ^~~~~~~
      |                                      |
      |                                      std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:37:47: error: cannot convert 'std::vector<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<std::__cxx11::basic_string<char> >*'
   37 |       return walk(cx tx, cy - 1, ty, indices, result);
      |                                               ^~~~~~
      |                                               |
      |                                               std::vector<std::__cxx11::basic_string<char> >*
a.cc:12:76: note:   initializing argument 5 of 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, std::vector<std::__cxx11::basic_string<char> >*)'
   12 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:43:19: error: expected ')' before 'tx'
   43 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:43:36: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   43 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                    ^~~~~~~
      |                                    |
      |                                    std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:43:45: error: cannot convert 'std::vector<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<std::__cxx11::basic_string<char> >*'
   43 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                             ^~~~~~
      |                                             |
      |                                             std::vector<std::__cxx11::basic_string<char> >*
a.cc:12:76: note:   initializing argument 5 of 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, std::vector<std::__cxx11::basic_string<char> >*)'
   12 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:47:19: error: expected ')' before 'tx'
   47 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:47:36: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   47 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                    ^~~~~~~
      |                                    |
      |                                    std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:47:45: error: cannot convert 'std::vector<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<std::__cxx11::basic_string<char> >*'
   47 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                             ^~~~~~
      |                                             |
      |                                             std::vector<std::__cxx11::basic_string<char> >*
a.cc:12:76: note:   initializing argument 5 of 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, std::vector<std::__cxx11::basic_string<char> >*)'
   12 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:51:19: error: expected ')' before 'tx'
   51 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:51:36: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   51 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                    ^~~~~~~
      |                                    |
      |                                    std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:51:45: error: cannot convert 'std::vector<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<std::__cxx11::basic_string<char> >*'
   51 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                             ^~~~~~
      |                                             |
      |                                             std::vector<std::__cxx11::basic_string<char> >*
a.cc:12:76: note:   initializing argument 5 of 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, std::vector<std::__cxx11::basic_string<char> >*)'
   12 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:55:19: error: expected ')' before 'tx'
   55 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:55:36: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   55 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                    ^~~~~~~
      |                                    |
      |                                    std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:55:45: error: cannot convert 'std::vector<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<std::__cxx11::basic_string<char> >*'
   55 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                                             ^~~~~~
      |                                             |
      |                                             std::vector<std::__cxx11::basic_string<char> >*
a.cc:12:76: note:   initializing argument 5 of 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, std::vector<std::__cxx11::basic_string<char> >*)'
   12 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc: In function 'int main()':
a.cc:77:14: error: expected ';' before '&' token
   77 |   for (auto p&: result) {
      |              ^
      |              ;
a.cc:77:15: error: expected primary-expression before ':' token
   77 |   for (auto p&: result) {
      |               ^
a.cc:77:15: error: expected ';' before ':' token
   77 |   for (auto p&: result) {
      |               ^
      |               ;
a.cc:77:15: error: expected primary-expression before ':' token
a.cc:77:15: error: expected ')' before ':' token
   77 |   for (auto p&: result) {
      |       ~       ^
      |               )
a.cc:77:15: error: expected primary-expression before ':' token