func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, m, cnt[100005], root, par[100005], br[100005], st[100005], brcnt;   vector<long long> a[100005];   pair<long long, long long> vert[100005];   map<pair<long long, long long>, long long> mm;   set<long long> brcl;   long long tmp = 1;   void dfs(long long v) {     if (a[v].size() > 0)       for (long long i = 0; i <= a[v].size() - 1; ++i) {         if (v == root) {           brcnt++;           st[brcnt] = tmp;         }         if (a[v][i] != par[v]) {           br[a[v][i]] = brcnt;           mm[make_pair(v, a[v][i])] = tmp++;           par[a[v][i]] = v;           dfs(a[v][i]);         }       }   }   inline long long finddist(long long req1, long long req2) {     if (brcl.empty()) return req2 - req1 + 1;     set<long long>::iterator curr = (brcl.lower_bound(req2));     if (*curr == req2) return -1;     if (curr == brcl.begin()) return req2 - req1 + 1;     curr--;     if (*curr >= req1 && *curr <= req2)       return -1;     else       return req2 - req1 + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n - 1; ++i) {       long long u, v;       cin >> u >> v;       cnt[u]++;       cnt[v]++;       if (cnt[u] > 2)         root = u;       else if (cnt[v] > 2)         root = v;       a[u].push_back(v);       a[v].push_back(u);       vert[i] = make_pair(u, v);     }     if (root == 0) root = 1;     par[root] = 0;     dfs(root);     for (long long i = 1; i <= n - 1; ++i)       if (vert[i].second == par[vert[i].first])         swap(vert[i].first, vert[i].second);     cin >> m;     for (long long loop = 1; loop <= m; ++loop) {       long long ty, id;       cin >> ty >> id;       if (ty == 1) {         long long edge = mm[vert[id]];         set<long long>::iterator it = brcl.find(edge);         brcl.erase(it);       } else if (ty == 2) {         long long edge = mm[vert[id]];         brcl.insert(edge);       } else {         long long en;         cin >> en;         if (en == id) {           cout << 0 << endl;           continue;         }         if (en == root) swap(en, id);         if (id == root) {           long long req1 = st[br[en]], req2 = mm[make_pair(par[en], en)];           cout << finddist(req1, req2) << endl;         } else if (br[id] == br[en]) {           if (mm[make_pair(par[en], en)] < mm[make_pair(par[id], id)])             swap(id, en);           long long v;           for (long long i = 0; i <= a[id].size() - 1; ++i)             if (a[id][i] != par[id]) v = a[id][i];           long long req1 = mm[make_pair(id, v)],                     req2 = mm[make_pair(par[en], en)];           cout << finddist(req1, req2) << endl;         } else {           long long req1 = st[br[en]], req2 = mm[make_pair(par[en], en)];           long long dist = finddist(req1, req2);           req1 = st[br[id]], req2 = mm[make_pair(par[id], id)];           cout << ((dist == -1 || finddist(req1, req2) == -1)                        ? -1                        : (finddist(req1, req2) + dist))                << endl;         }       }     }     return 0;   }   