Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
??
struct room{
????int roomnum;
????bool visited;
??????
????bool operator>(const room compared) const
????{
????????return roomnum > compared.roomnum;
????}
????bool operator<(const room compared) const
????{
????????return roomnum < compared.roomnum;
????}
};
??
struct compar{
????long long int cost, 
  int loc_x, loc_y;
????bool is_ns;
??????
????bool operator>(const compar compared) const
????{
????????return cost > compared.cost;
????}
????bool operator<(const compar compared) const
????{
????????return cost < compared.cost;
????}
};
??
int m, n, k;
vector<room> ns[100001], ew[100001];
priority_queue<compar, vector<compar>, greater<compar> > sr;
??
long long int dijk()
{
????if(!ns[1].size())
????????return -1;
??????
????compar start = {(ns[1].begin())->roomnum - 1, 1, (ns[1].begin())->roomnum, true};
????sr.push(start);
??????
????while(!sr.empty()){
????????compar now = sr.top();
????????sr.pop();
??????????
????????if(now.loc_x == m && now.loc_y == n)
????????????return now.cost;
??????????
????????vector<room>::iterator p;
????????if(now.is_ns){
????????????room pp = {now.loc_y, false};
????????????p = lower_bound(ns[now.loc_x].begin(), ns[now.loc_x].end(), pp);
??????????????
????????????if(!p->visited){
????????p->visited = true;
????????if(p != ns[now.loc_x].begin()){
????????????compar next = {now.cost + now.loc_y - (p - 1)->roomnum, now.loc_x, (p - 1)->roomnum, true};
????????????sr.push(next);
????????}
????????if(p != ns[now.loc_x].end() - 1){
????????????compar next = {now.cost + (p + 1)->roomnum - now.loc_y, now.loc_x, (p + 1)->roomnum, true};
????????????sr.push(next);
????????}
????????compar next = {now.cost + 1, now.loc_x, now.loc_y, false};
????????sr.push(next);
????????????}
????????}
????????else{
????????????room pp = {now.loc_x, false};
????????????p = lower_bound(ew[now.loc_y].begin(), ew[now.loc_y].end(), pp);
??
????????????if(!p->visited){
????????p->visited = true;
????????if(p != ew[now.loc_y].begin()){
????????????compar next = {now.cost + now.loc_x - (p - 1)->roomnum, (p - 1)->roomnum, now.loc_y, false};
????????????sr.push(next);
????????}
????????if(p != ew[now.loc_y].end() - 1){
????????????compar next = {now.cost + (p + 1)->roomnum - now.loc_x, (p + 1)->roomnum, now.loc_y, false};
????????????sr.push(next);
????????}
????????compar next = {now.cost + 1, now.loc_x, now.loc_y, true};
????????sr.push(next);
????????????}
????????}
????}
??
????return -1;
}
??
int main()
{
????scanf("%d%d%d", &m, &n, &k);
????for(int i = 0; i < k; i++){
????????int x, y;
????????scanf("%d%d", &x, &y);
????????room x_in = {y, false};
????????ns[x].push_back(x_in);
????????room y_in = {x, false};
????????ew[y].push_back(y_in);
????}
????if(!ns[m].size() || (ns[m].end() - 1)->roomnum != n){
????????room x_in = {n, false};
????????ns[m].push_back(x_in);
????}
????if(!ew[n].size() || (ew[n].end() - 1)->roomnum != m){
????????room y_in = {m, false};
????????ew[n].push_back(y_in);
????}
??????
????for(int i = 1; i <= m; i++)
????????sort(ns[i].begin(), ns[i].end());
????for(int i = 1; i <= n; i++)
????????sort(ew[i].begin(), ew[i].end());
??????
????printf("%lld\n", dijk());
????return 0;
}

Compiler output:
a.cc:8:1: error: expected unqualified-id before '?' token
    8 | ??
      | ^
a.cc:22:1: error: expected unqualified-id before '?' token
   22 | ??
      | ^
a.cc:37:1: error: expected unqualified-id before '?' token
   37 | ??
      | ^
a.cc:39:8: error: 'room' was not declared in this scope
   39 | vector<room> ns[100001], ew[100001];
      |        ^~~~
a.cc:39:12: error: template argument 1 is invalid
   39 | vector<room> ns[100001], ew[100001];
      |            ^
a.cc:39:12: error: template argument 2 is invalid
a.cc:40:16: error: 'compar' was not declared in this scope
   40 | priority_queue<compar, vector<compar>, greater<compar> > sr;
      |                ^~~~~~
a.cc:40:31: error: 'compar' was not declared in this scope
   40 | priority_queue<compar, vector<compar>, greater<compar> > sr;
      |                               ^~~~~~
a.cc:40:37: error: template argument 1 is invalid
   40 | priority_queue<compar, vector<compar>, greater<compar> > sr;
      |                                     ^
a.cc:40:37: error: template argument 2 is invalid
a.cc:40:48: error: 'compar' was not declared in this scope
   40 | priority_queue<compar, vector<compar>, greater<compar> > sr;
      |                                                ^~~~~~
a.cc:40:54: error: template argument 1 is invalid
   40 | priority_queue<compar, vector<compar>, greater<compar> > sr;
      |                                                      ^
a.cc:40:56: error: template argument 1 is invalid
   40 | priority_queue<compar, vector<compar>, greater<compar> > sr;
      |                                                        ^
a.cc:40:56: error: template argument 2 is invalid
a.cc:40:56: error: template argument 3 is invalid
a.cc:41:1: error: expected unqualified-id before '?' token
   41 | ??
      | ^
a.cc:98:1: error: expected unqualified-id before '?' token
   98 | ??
      | ^