func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n = 0, m = 0, q = 0;   long long ans = 0;   vector<vector<int>> G = vector<std::vector<int>>(100001);   vector<long long> f(112345), fa(100001), dep(100001), val(100001), sz(100001),       s(100001);   long long F(long long x) { return x == f[x] ? x : (f[x] = F(f[x])); }   void dfs(long long u, long long ff) {     sz[u] = 1;     dep[u] = dep[ff] + 1;     fa[u] = ff;     for (int i = 0; i < G[u].size(); ++i) {       long long v = G[u][i];       if (v == ff) {         continue;       }       dfs(v, u);       sz[u] += sz[v];       val[u] += sz[v] * sz[v];     }     val[u] += (n - sz[u]) * (n - sz[u]);     ans -= val[u];   }   void merge(int x, int y) {     ans -= s[x] * (s[x] - 1) * (s[x] - 2);     ans -= s[y] * (s[y] - 1) * (s[y] - 2);     ans -= s[x] * (s[x] - 1) * (n - s[x]) * 2;     ans -= s[y] * (s[y] - 1) * (n - s[y]) * 2;     ans -= (n - s[x]) * (n - s[x]) * s[x];     ans -= (n - s[y]) * (n - s[y]) * s[y];     ans += val[x] * s[x];     ans += val[y] * s[y];     val[x] += val[y] - sz[y] * sz[y] - (n - sz[y]) * (n - sz[y]);     s[x] += s[y];     f[y] = x;     ans += s[x] * (s[x] - 1) * (s[x] - 2);     ans += s[x] * (s[x] - 1) * (n - s[x]) * 2;     ans += (n - s[x]) * (n - s[x]) * s[x];     ans -= val[x] * s[x];   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       G[i] = std::vector<int>();       s[i] = 1;       f[i] = i;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     ans = 1LL * n * (n - 1) * (n - 1);     dfs(1, 0);     cout << ans << endl;     cin >> q;     while (q-- > 0) {       int u, v;       cin >> u >> v;       u = F(u);       v = F(v);       while (u != v) {         if (dep[u] < dep[v]) {           int o = v;           v = u;           u = o;         }         merge(F(fa[u]), u);         u = F(u);       }       cout << ans << endl;     }     return 0;   }   