func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 3002;   int dfn[N], low[N], c;   bool ipt[N];   pair<int, int> edge[N];   vector<pair<int, int> > p[N];   void tarjan(int x, int pre) {     dfn[x] = low[x] = ++c;     for (__typeof(p[x].begin()) it = p[x].begin(); it != p[x].end(); ++it) {       if (pre == (*it).second) continue;       int y = (*it).first;       if (dfn[y]) {         low[x] = min(low[x], dfn[y]);       } else {         tarjan(y, (*it).second);         low[x] = min(low[x], low[y]);         if (dfn[x] < low[y]) ipt[(*it).second] = 1;       }     }   }   int n, m, k, f[N];   void init() {     for (int i = 1; i <= n; ++i) f[i] = i;   }   int finds(int x) { return x == f[x] ? x : f[x] = finds(f[x]); }   void unions(int x, int y) {     x = finds(x);     y = finds(y);     f[x] = y;   }   bool vis[N];   int dfs(int x, int y, int deep) {     if (x == y) return deep;     vis[x] = true;     for (__typeof(p[x].begin()) e = p[x].begin(); e != p[x].end(); ++e)       if (!vis[e->first]) {         int g = dfs(e->first, y, deep + 1);         if (g != -1) return g;       }     return -1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int x, y;     for (int i = 0; i < m; ++i) {       cin >> edge[i].first >> edge[i].second;       x = edge[i].first;       y = edge[i].second;       p[x].push_back(make_pair(y, i));       p[y].push_back(make_pair(x, i));     }     init();     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i, -1);     for (int i = 0; i < m; ++i)       if (!ipt[i]) {         unions(edge[i].first, edge[i].second);       }     for (int i = 0; i <= n; ++i) p[i].clear();     for (int i = 0; i < m; ++i)       if (ipt[i]) {         p[finds(f[edge[i].first])].push_back(             make_pair(finds(f[edge[i].second]), -1));         p[finds(f[edge[i].second])].push_back(             make_pair(finds(f[edge[i].first]), -1));       }     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> x >> y;       for (int i = 0; i <= n; ++i) vis[i] = false;       cout << dfs(finds(f[x]), finds(f[y]), 0) << endl;     }     return 0;   }   