func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   int a[200000 + 5];   int d[200000 + 5];   set<pair<int, int> > s;   set<pair<int, int> >::iterator it;   void djikstra() {     int u, v;     fill(d, d + n + 2, (int)100000000);     d[1] = 0;     s.insert(make_pair(d[1], 1));     while (!s.empty()) {       it = s.begin();       u = (*it).second;       s.erase(it);       v = a[u];       if (d[v] > (d[u] + 1)) {         if (d[v] != (int)100000000) s.erase(s.find(make_pair(d[v], v)));         d[v] = d[u] + 1;         s.insert(make_pair(d[v], v));       }       v = u - 1;       if (v >= 1 && d[v] > (d[u] + 1)) {         if (d[v] != (int)100000000) s.erase(s.find(make_pair(d[v], v)));         d[v] = d[u] + 1;         s.insert(make_pair(d[v], v));       }       v = u + 1;       if (v <= n && d[v] > (d[u] + 1)) {         if (d[v] != (int)100000000) s.erase(s.find(make_pair(d[v], v)));         d[v] = d[u] + 1;         s.insert(make_pair(d[v], v));       }     }   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     djikstra();     for (i = 1; i <= n; i++) printf( %d  , d[i]);     return 0;   }   