func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10, LOG = 20;   int n, q, F[N], T[N], P[N], D[N], Par[LOG][N];   pair<int, int> Q[N];   vector<int> Adj[N], Ap[N], V[N << 2];   void Pre(int v) {     for (int i = 1; i < LOG; i++) Par[i][v] = Par[i - 1][Par[i - 1][v]];     for (auto X : Adj[v])       if (X != Par[0][v]) Par[0][X] = v, D[X] = D[v] + 1, Pre(X);   }   int LCA(int v, int u) {     if (D[v] < D[u]) return (LCA(u, v));     for (int i = 0; i < LOG; i++)       if ((D[v] - D[u]) & (1 << i)) v = Par[i][v];     if (v == u) return (v);     for (int i = LOG - 1; ~i; i--)       if (Par[i][v] != Par[i][u]) v = Par[i][v], u = Par[i][u];     return (Par[0][v]);   }   int Dist(int v, int u) { return (D[v] + D[u] - 2 * D[LCA(v, u)]); }   int Find(int v) {     if (P[v] < 0) return (v);     return (Find(P[v]));   }   void Add(int i, int le, int ri, int id = 1, int l = 0, int r = q + 2) {     if (ri <= l || r <= le) return;     if (le <= l && r <= ri) {       V[id].push_back(i);       return;     }     Add(i, le, ri, id * 2, l, (l + r) >> 1);     Add(i, le, ri, id * 2 + 1, (l + r) >> 1, r);   }   void DFS(int id, int l = 0, int r = q + 2) {     vector<pair<int, pair<int, int> > > Op;     for (auto i : V[id])       if (Find(F[i]) != Find(T[i])) {         int v = Find(F[i]), u = Find(T[i]);         if (P[v] > P[u]) swap(v, u);         Op.push_back({u, {v, P[u]}});         P[v] += P[u];         P[u] = v;       }     if (r - l == 1)       if (Q[l].first > 0) {         if (Find(Q[l].first) == Find(Q[l].second))           printf( %d n , Dist(Q[l].first, Q[l].second));         else           puts( -1 );       }     if (r - l > 1) DFS(id * 2, l, (l + r) >> 1), DFS(id * 2 + 1, (l + r) >> 1, r);     reverse(Op.begin(), Op.end());     for (auto X : Op)       P[X.first] = X.second.second, P[X.second.first] -= P[X.first];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++)       scanf( %d%d , &F[i], &T[i]), Ap[i].push_back(0), Adj[F[i]].push_back(T[i]),           Adj[T[i]].push_back(F[i]);     scanf( %d , &q);     int tp, v, u;     for (int i = 1; i <= q; i++) {       scanf( %d%d , &tp, &v);       if (tp < 3)         Ap[v].push_back(i);       else         scanf( %d , &u), Q[i] = {v, u};     }     for (int i = 1; i < n; i++) {       Ap[i].push_back(q + 1);       for (int j = 1; j < Ap[i].size(); j += 2) Add(i, Ap[i][j - 1], Ap[i][j]);     }     memset(P, -1, sizeof(P));     Pre(1);     DFS(1);     return (0);   }   