func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<int> lista;   vector<int> posicion;   vector<set<int> > s;   void genera(int u, int p, int lis, int pos) {     lista[u] = lis;     posicion[u] = pos;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++)       if (ar[i] != p) genera(ar[i], u, lis, pos + 1);   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     g = vector<vector<int> >(n);     vector<pair<int, int> > arista;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);       arista.push_back(pair<int, int>(u, v));     }     int umax = 0;     lista = posicion = vector<int>(n);     for (int u = 1; u < n; u++)       if (int(g[u].size()) > int(g[umax].size())) umax = u;     {       lista[umax] = posicion[umax] = -1;       vector<int> &ar = g[umax];       for (int i = 0; i < int(ar.size()); i++) genera(ar[i], umax, i, 1);       s = vector<set<int> >(int(ar.size()));     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int tipo;       cin >> tipo;       if (tipo == 1) {         int indar;         cin >> indar;         indar--;         int u;         if (posicion[arista[indar].first] < posicion[arista[indar].second])           u = arista[indar].second;         else           u = arista[indar].first;         s[lista[u]].erase(posicion[u]);       } else if (tipo == 2) {         int indar;         cin >> indar;         indar--;         int u;         if (posicion[arista[indar].first] < posicion[arista[indar].second])           u = arista[indar].second;         else           u = arista[indar].first;         s[lista[u]].insert(posicion[u]);       } else {         int u, v;         cin >> u >> v;         u--;         v--;         if (posicion[u] > posicion[v]) swap(u, v);         if (u == umax) {           if (v == umax) {             cout << 0 << endl;           } else {             set<int>::iterator it = s[lista[v]].upper_bound(posicion[v]);             if (it == s[lista[v]].begin())               cout << posicion[v] << endl;             else               cout << -1 << endl;           }         } else {           set<int>::iterator itu = s[lista[u]].upper_bound(posicion[u]);           set<int>::iterator itv = s[lista[v]].upper_bound(posicion[v]);           if (lista[u] == lista[v]) {             if (itu == itv)               cout << posicion[v] - posicion[u] << endl;             else               cout << -1 << endl;           } else {             int du;             if (itu == s[lista[u]].begin())               du = posicion[u];             else               du = -1;             int dv;             if (itv == s[lista[v]].begin())               dv = posicion[v];             else               dv = -1;             if (du != -1 and dv != -1)               cout << du + dv << endl;             else               cout << -1 << endl;           }         }       }     }   }   