#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; void solve() { int n; cin >> n; vector> g(n); rep(i, 0, n - 1) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } vector childs(n); { auto dfs = [&](auto self, int nw, int pr) -> void { int res = 0; for (int nx : g[nw]) { if (nx == pr) continue; self(self, nx, nw); chmax(res, childs[nx] + 1); } childs[nw] = res; }; dfs(dfs, 0, -1); } ll ans = 0; { auto dfs = [&](auto self, int nw, int pr, int p_val) -> void { vector v = {p_val}; for (int nx : g[nw]) { if (nx == pr) continue; v.push_back(childs[nx] + 1); } auto sv = v; rep(i, 0, v.size() - 1) chmax(sv[i + 1], sv[i]); auto rsv = v; for (int i = v.size() - 1; i > 0; i--) chmax(rsv[i - 1], rsv[i]); rsv.push_back(0); int it = 0; for (int nx : g[nw]) { if (nx == pr) continue; self(self, nx, nw, max(sv[it], rsv[it + 2]) + 1); it++; } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); rep(i, 0, v.size()) { chmax(ans, (i + 1) * v[i] + 1); } }; dfs(dfs, 0, -1, 0); } cout << ans << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }