func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   constexpr int inf = 1e9;   using P = pair<int, int>;   template <typename T>   void printv(const vector<T> &v) {     int sz = v.size();     for (int i = 0; i < sz; i++) {       cout << v[i] <<    n [i == sz - 1];     }   }   using Graph = vector<vector<int>>;   const int MAX_N = 3010;   Graph g(MAX_N);   vector<vector<int>> dist(MAX_N, vector<int>(MAX_N, inf));   vector<vector<int>> ch(MAX_N, vector<int>(MAX_N));   int dfs(int r, int cur, int pre) {     ch[r][cur] = 1;     for (auto nxt : g[cur]) {       if (nxt == pre) continue;       ch[r][cur] += dfs(r, nxt, cur);     }     return ch[r][cur];   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<P> ps;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       ps.push_back(P(u, v));       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 0; i < n; i++) {       queue<int> que;       que.push(i);       dist[i][i] = 0;       while (!que.empty()) {         int v = que.front();         que.pop();         for (auto nxt : g[v]) {           if (dist[i][nxt] != inf) continue;           dist[i][nxt] = dist[i][v] + 1;           que.push(nxt);         }       }     }     for (int i = 0; i < n; i++) {       dfs(i, i, -1);     }     vector<vector<P>> cs(n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cs[dist[i][j]].push_back(P(i, j));       }     }     vector<vector<ll>> dp(n, vector<ll>(n));     for (int d = 0; d < n - 1; d++) {       for (auto p : cs[d]) {         int u = p.first, v = p.second;         for (auto nxt : g[u]) {           if (dist[u][nxt] + dist[u][v] != dist[v][nxt]) continue;           ll x = ch[nxt][v], y = ch[u][nxt];           dp[nxt][v] = max(dp[nxt][v], dp[u][v] + x * y);           dp[v][nxt] = max(dp[v][nxt], dp[u][v] + x * y);         }         for (auto nxt : g[v]) {           if (dist[v][nxt] + dist[u][v] != dist[u][nxt]) continue;           ll x = ch[nxt][u], y = ch[v][nxt];           dp[nxt][u] = max(dp[nxt][u], dp[u][v] + x * y);           dp[u][nxt] = max(dp[u][nxt], dp[u][v] + x * y);         }       }     }     ll ret = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) ret = max(ret, dp[i][j]);     cout << ret << endl;   }   