func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     int x;     int y;     node(int a, int b) {       x = a;       y = b;     }   };   int n, m, k, flag;   vector<node> v;   int vis[10005], dis[10005];   const int inf = 0x3f3f3f3f;   int spfa() {     memset(dis, inf, sizeof(dis));     queue<int> q;     q.push(0);     dis[0] = 0;     while (!q.empty()) {       int Now = q.front();       q.pop();       vis[Now] = 0;       for (int i = 0; i < k; i++) {         if (i == Now) continue;         node to = v[i];         node now = v[Now];         int cost = inf;         if (abs(now.x - to.x) + abs(now.y - to.y) == 1)           cost = 0;         else if (abs(now.x - to.x) <= 2 || abs(now.y - to.y) <= 2)           cost = 1;         if (dis[i] > dis[Now] + cost) {           dis[i] = dis[Now] + cost;           if (!vis[i]) {             q.push(i);           }         }       }     }     if (dis[k - 1] < inf) return dis[k - 1];     return -1;   }   int main() {     ios::sync_with_stdio(false);     ;     while (cin >> n >> m >> k) {       flag = 0;       v.clear();       for (int i = 0; i < k; i++) {         int x, y;         cin >> x >> y;         v.push_back(node(x, y));         if (x == n && y == m) flag = 1;       }       if (!flag) {         k++;         v.push_back(node(n + 1, m + 1));       }       cout << spfa() << endl;     }   }   