func_code_string: #include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = INF * (long long)INF;   const int MAX = 3000 + 47;   vector<int> g[MAX];   vector<int> S;   int L[MAX];   int U[MAX];   queue<int> q;   int D[MAX];   int n;   void dfs(int v, int p) {     if (U[v] == 1) {       int sz = (int)S.size() - 1;       L[v] = 1;       while (S[sz] != v) {         L[S[sz]] = 1;         sz--;       }       return;     }     U[v] = 1;     S.push_back(v);     for (int i = (0); i < ((int)g[v].size()); i++) {       int to = g[v][i];       if (to == p) continue;       dfs(to, v);     }     S.pop_back();     U[v] = 2;   }   void bfs() {     for (int i = (0); i < (n); i++) D[i] = INF;     for (int i = (0); i < (n); i++) {       if (!L[i]) continue;       q.push(i);       D[i] = 0;     }     while (!q.empty()) {       int v = q.front();       q.pop();       for (int i = (0); i < ((int)g[v].size()); i++) {         int to = g[v][i];         if (D[to] != INF) continue;         D[to] = D[v] + 1;         q.push(to);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = (0); i < (n); i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(0, 0);     bfs();     for (int i = (0); i < (n); i++) {       cout << D[i] <<    ;     }     cout << endl;   }   