func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 10;   int to[maxn << 1], nex[maxn << 1], head[maxn << 1], e, cnt;   int u[maxn << 1], v[maxn << 1];   int dep[maxn << 1], siz[maxn << 1], son[maxn << 1], top[maxn << 1],       fa[maxn << 1], id[maxn << 1];   int sum[maxn << 2];   int n;   void add(int x, int y) {     to[++e] = y;     nex[e] = head[x];     head[x] = e;   }   int ls(int p) { return p << 1; }   int rs(int p) { return p << 1 | 1; }   void push_up(int p) { sum[p] = sum[ls(p)] + sum[rs(p)]; }   int query(int p, int l, int r, int qx, int qy) {     if (qx <= l && qy >= r) {       return sum[p];     }     int res = 0;     int mid = (l + r) >> 1;     if (qx <= mid) res = res + query(ls(p), l, mid, qx, qy);     if (qy > mid) {       res = res + query(rs(p), mid + 1, r, qx, qy);     }     return res;   }   void update(int p, int l, int r, int pos, int val) {     if (l == r) {       sum[p] = val;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid) {       update(ls(p), l, mid, pos, val);     }     if (pos > mid) update(rs(p), mid + 1, r, pos, val);     push_up(p);   }   int getrange(int x, int y) {     int ans = 0;     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       ans = ans + query(1, 1, n, id[top[x]], id[x]);       x = fa[top[x]];     }     if (dep[x] > dep[y]) swap(x, y);     ans = ans + query(1, 1, n, id[x] + 1, id[y]);     return ans;   }   void dfs1(int x, int f, int deep) {     fa[x] = f;     siz[x] = 1;     dep[x] = deep;     int maxson = -1;     for (int i = head[x]; i; i = nex[i]) {       int y = to[i];       if (y == f) continue;       dfs1(y, x, deep + 1);       siz[x] += siz[y];       if (maxson < siz[y]) {         maxson = siz[y];         son[x] = y;       }     }   }   void dfs2(int x, int topf) {     id[x] = ++cnt;     top[x] = topf;     if (!son[x]) return;     dfs2(son[x], topf);     for (int i = head[x]; i; i = nex[i]) {       int y = to[i];       if (y == fa[x] || y == son[x]) continue;       dfs2(y, y);     }   }   int lca(int x, int y) {     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) {         swap(x, y);       }       x = fa[top[x]];     }     if (dep[x] > dep[y]) swap(x, y);     return x;   }   int main() {     memset(sum, 0, sizeof(sum));     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &u[i], &v[i]);       add(u[i], v[i]);       add(v[i], u[i]);     }     dfs1(1, 0, 1);     dfs2(1, 0);     int m;     scanf( %d , &m);     while (m--) {       int op;       scanf( %d , &op);       if (op == 1) {         int x;         scanf( %d , &x);         if (dep[u[x]] > dep[v[x]])           update(1, 1, n, id[u[x]], 0);         else           update(1, 1, n, id[v[x]], 0);       }       if (op == 2) {         int x;         scanf( %d , &x);         if (dep[u[x]] > dep[v[x]]) {           update(1, 1, n, id[u[x]], 1);         } else {           update(1, 1, n, id[v[x]], 1);         }       }       if (op == 3) {         int x, y;         scanf( %d%d , &x, &y);         if (getrange(x, y)) {           printf( -1 n );         } else {           printf( %d n , dep[x] + dep[y] - 2 * dep[lca(x, y)]);         }       }     }   }   