func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int N = 510000, M = N << 1;   int n, hd[N], to[M], nxt[M], noedg = 1, size[N];   long long buc[N], f[N], ans = inf;   vector<int> app[N];   template <class T>   inline void read(T &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;     return;   }   inline void addEdg(int x, int y) {     nxt[++noedg] = hd[x], hd[x] = noedg, to[noedg] = y;     nxt[++noedg] = hd[y], hd[y] = noedg, to[noedg] = x;     return;   }   inline long long sq(long long x) { return x * x; }   void dfs(int now, int fa) {     size[now] = 1, f[now] = inf;     for (register int i = hd[now], v; i; i = nxt[i]) {       if ((v = to[i]) == fa) continue;       dfs(v, now), size[now] += size[v];     }     buc[0] = 0, app[now].push_back(0);     for (register int i = hd[now], v; i; i = nxt[i]) {       if ((v = to[i]) == fa) continue;       for (register int j = 0, sz = app[now].size(); j < sz; ++j)         ans = min(ans, buc[app[now][j]] + f[v] + sq(n - app[now][j] - size[v]));       if (buc[size[v]] == inf) app[now].push_back(size[v]);       buc[size[v]] = min(buc[size[v]], f[v]);       f[now] = min(f[now], f[v] + sq(size[now] - size[v]));     }     for (register int i = 0, sz = app[now].size(); i < sz; ++i)       buc[app[now][i]] = inf;     if (f[now] == inf) f[now] = 1;     return;   }   int main() {     int x, y;     read(n);     for (register int i = 1; i < n; ++i)       read(x), read(y), addEdg(x, y), buc[i] = inf;     dfs(1, 0);     cout << ((long long)n * (2 * n - 1) - ans) / 2;     return 0;     int qwq;   }   