func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<int> v;   vector<vector<int>> g;   int in[N], out[N], col[N], is[N], dp[18][N], depth[N], z;   struct node {     int l, r, id;     node(int a = 0, int b = 0, int c = 0) {       l = a;       r = b;       id = c;     }     bool operator<(const node& e) const {       int a = l / z, b = e.l / z;       if (a != b) return a < b;       if (a & 1) return r > e.r;       return r < e.r;     }   };   vector<node> q;   void dfs(int u, int p) {     dp[0][u] = p;     in[u] = v.size();     v.push_back(u);     for (int i = 1; i < 18; i++)       dp[i][u] = dp[i - 1][u] + 1 ? dp[i - 1][dp[i - 1][u]] : -1;     for (auto i : g[u])       if (i != p) depth[i] = depth[u] + 1, dfs(i, u);     out[u] = v.size();     v.push_back(u);   }   int lca(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     for (int i = 17; i + 1; i--)       if (depth[a] - (1 << i) >= depth[b]) a = dp[i][a];     if (a == b) return a;     for (int i = 17; i + 1; i--)       if (dp[i][a] != dp[i][b]) a = dp[i][a], b = dp[i][b];     return dp[0][a];   }   int main() {     int n;     scanf( %d , &n);     g.resize(n);     for (int i = 0; i < n; i++) scanf( %d , is + i);     for (int i = 0; i < n; i++) scanf( %d , col + i);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[--a].push_back(--b);       g[b].push_back(a);     }     dfs(0, -1);     scanf( %d , &n);     z = sqrt(v.size()) + 1;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       if (in[a] > in[b]) swap(a, b);       q.push_back(node(in[a] + 1, in[b], i));     }     sort(q.begin(), q.end());     long long ans[N] = {}, temp = 0, freq[N] = {};     int l = 0, r = -1;     unordered_map<int, int> mp[2];     for (auto i : q) {       if (i.l - 1 == i.r) continue;       while (r < i.r) {         r++;         int a = is[v[r]];         int b = col[v[r]];         if (freq[v[r]]++) {           temp -= mp[!a][b];           mp[a][b]--;         } else {           temp += mp[!a][b];           mp[a][b]++;         }       }       while (r > i.r) {         int a = is[v[r]];         int b = col[v[r]];         if (--freq[v[r]]) {           temp += mp[!a][b];           mp[a][b]++;         } else {           temp -= mp[!a][b];           mp[a][b]--;         }         r--;       }       while (l < i.l) {         int a = is[v[l]];         int b = col[v[l]];         if (--freq[v[l]]) {           temp += mp[!a][b];           mp[a][b]++;         } else {           temp -= mp[!a][b];           mp[a][b]--;         }         l++;       }       while (l > i.l) {         l--;         int a = is[v[l]];         int b = col[v[l]];         if (freq[v[l]]++) {           temp -= mp[!a][b];           mp[a][b]--;         } else {           temp += mp[!a][b];           mp[a][b]++;         }       }       int LCA = lca(v[i.l - 1], v[i.r]);       int lol = mp[!is[LCA]][col[LCA]];       ans[i.id] = temp + lol;     }     for (int i = 0; i < q.size(); i++) printf( %lld n , ans[i]);   }   