func_code_string: #include <bits/stdc++.h>   using namespace std;   int treeNo[111111];   vector<vector<int> > BIT;   vector<pair<int, int> > E[111111];   int in[111111];   int base[111111];   int P[111111], depth[111111];   void update(int x, int val, int id) {     for (; x < BIT[id].size(); x += (x & -x)) BIT[id][x] += val;   }   int read(int x, int id) {     int sum = 0;     for (; x; x -= (x & -x)) sum += BIT[id][x];     return sum;   }   void dfs(int first, int par, int d, int id) {     P[first] = par;     depth[first] = d;     BIT[id].push_back(0);     treeNo[first] = id;     for (int i = 0; i < E[first].size(); i++) {       int u = E[first][i].first;       if (u == par) continue;       dfs(u, first, d + 1, id);       base[E[first][i].second] = u;     }   }   int main() {     int N;     cin >> N;     int u, first;     for (int i = 1; i < N; i++) {       cin >> u >> first;       E[u].push_back({first, i});       E[first].push_back({u, i});       in[u]++;       in[first]++;     }     int root = 0;     for (int i = 1; i <= N; i++)       if (in[i] > 2) root = i;     if (root == 0)       for (int i = 1; i <= N; i++)         if (in[i] == 1) root = i;     BIT.resize(E[root].size());     for (int i = 0; i < E[root].size(); i++) {       BIT[i].push_back(0);       dfs(E[root][i].first, root, 1, i);       base[E[root][i].second] = E[root][i].first;     }     int Q, t;     cin >> Q;     while (Q--) {       scanf( %d %d , &t, &first);       if (t == 3) {         scanf( %d , &u);         if (u == root or first == root) {           if (u == root) swap(u, first);           int sum = read(depth[u], treeNo[u]);           if (sum == 0)             printf( %d n , depth[u]);           else             printf( -1 n );         } else if (treeNo[u] == treeNo[first]) {           if (depth[u] == depth[first])             printf( 0 n );           else {             if (depth[first] < depth[u]) swap(u, first);             int sum =                 read(depth[first], treeNo[first]) - read(depth[u], treeNo[first]);             if (sum == 0)               printf( %d n , depth[first] - depth[u]);             else               printf( -1 n );           }         } else {           int sum = read(depth[u], treeNo[u]) + read(depth[first], treeNo[first]);           if (sum == 0)             printf( %d n , depth[first] + depth[u]);           else             printf( -1 n );         }       } else if (t == 2) {         int b = base[first];         update(depth[b], 1, treeNo[b]);       } else if (t == 1) {         int b = base[first];         update(depth[b], -1, treeNo[b]);       }     }   }   