func_code_string: #include <bits/stdc++.h>   using namespace std;   int par[20][100001], dep[100001], lg[100001], sizes[100001];   bool isParent[100001];   vector<int> adj[100001];   void dfs(int u) {     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != par[0][u]) {         isParent[u] = true;         dep[v] = dep[u] + 1;         par[0][v] = u;         dfs(v);       }     }   }   int subtree(int u) {     if (sizes[u] == -1) {       sizes[u] = 1;       if (isParent[u]) {         for (int i = 0; i < adj[u].size(); i++) {           int v = adj[u][i];           if (v != par[0][u]) sizes[u] += subtree(v);         }       }     }     return sizes[u];   }   void buildLCA(int root, int n) {     memset(par, -1, sizeof par);     memset(sizes, -1, sizeof sizes);     memset(isParent, false, sizeof isParent);     dep[root] = 0;     dfs(root);     for (int i = 2; i < n; i++) lg[i] = lg[i >> 1] + 1;     for (int i = 1; (1 << i) < n; i++)       for (int u = 0; u < n; u++)         if ((1 << i) <= dep[u]) par[i][u] = par[i - 1][par[i - 1][u]];     subtree(root);   }   int climb(int u, int k) {     if (dep[u] < k) return -1;     for (; k > 0; k -= (1 << lg[k])) u = par[lg[k]][u];     return u;   }   int lca(int a, int b) {     if (dep[a] < dep[b])       b = climb(b, dep[b] - dep[a]);     else       a = climb(a, dep[a] - dep[b]);     for (int k = lg[dep[a]]; k >= 0 && a != b; k--)       if (par[k][a] != par[k][b]) {         a = par[k][a];         b = par[k][b];       }     if (a != b && dep[a] > 0) {       a = par[0][a];       b = par[0][b];     }     return a == b ? a : -1;   }   int dist(int u, int v) {     int L = lca(u, v);     return L == -1 ? -1 : dep[u] + dep[v] - 2 * dep[L];   }   int main() {     int n, m;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     buildLCA(1, n + 1);     cin >> m;     while (m--) {       int a, b;       cin >> a >> b;       if (a != b) {         int l = lca(a, b), distance = dist(a, b);         if (distance % 2 == 0) {           if (dep[a] != dep[b]) {             int deepernode;             if (dep[a] > dep[b])               deepernode = a;             else               deepernode = b;             int mid1 = climb(deepernode, distance / 2),                 mid2 = climb(deepernode, distance / 2 - 1);             cout << sizes[mid1] - sizes[mid2] << endl;           } else {             int aa = climb(a, dist(a, l) - 1), bb = climb(b, dist(a, l) - 1);             cout << n - sizes[aa] - sizes[bb] << endl;           }         } else           cout << 0 << endl;       } else         cout << n << endl;     }   }   