func_code_string: #include <bits/stdc++.h>   using namespace std;   long double PI = 3.14159265359;   long long inf = 1000000000000000007;   long long mod = 1000000007;   long long mod1 = 998244353;   const bool multi = 0;   long long DP[500007];   long long s[500007];   vector<long long> G[500007];   long long ans = inf, n;   void dfs(long long v, long long o) {     s[v] = 1;     vector<pair<pair<long long, long long>, long long>> DPs;     DP[v] = inf;     if ((long long)(G[v]).size() == 1) DP[v] = 0;     long long sum = 0;     for (auto u : G[v]) {       if (u == o) continue;       dfs(u, v);       s[v] += s[u];       DPs.push_back({{-2 * s[u], 2 * DP[u] + s[u] * (s[u] + 1)}, u});     }     sort(DPs.begin(), DPs.end());     vector<pair<long long, long long>> CHT;     for (auto x : DPs) {       long long l = 0, r = (long long)(CHT).size() - 1, sr;       long long S = n - s[x.second];       ans =           min(ans, 2 * DP[x.second] + (n - s[x.second]) * (n - s[x.second] - 1));       while (l <= r) {         sr = (l + r) / 2;         long long L =             2 * DP[x.second] + S * (S - 1) + S * CHT[sr].first + CHT[sr].second;         ans = min(ans, L);         if (sr + 1 == (long long)(CHT).size()) break;         long long R = 2 * DP[x.second] + S * (S - 1) + S * CHT[sr + 1].first +                       CHT[sr + 1].second;         ans = min(ans, R);         if (L <= R)           r = sr - 1;         else           l = sr + 1;       }       if ((long long)(CHT).size() == 0 || x.first.first != CHT.back().first)         CHT.push_back({x.first.first, x.first.second});       DP[v] = min(DP[v], DP[x.second] +                              (s[v] - s[x.second]) * (s[v] - s[x.second] - 1) / 2);     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt;     if (multi)       cin >> tt;     else       tt = 1;     while (tt--) {       long long a, b;       cin >> n;       for (long long i = 1; i < n; i++) {         cin >> a >> b;         G[a].push_back(b);         G[b].push_back(a);       }       dfs(1, -1);       ans /= 2;       cout << ans + 2 * (n * (n - 1) / 2 - ans);     }     return 0;   }   