#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; namespace cho { template struct lr_dp_table { std::vector dp_l, dp_r; int sz; lr_dp_table(const std::vector& v) { sz = v.size(); dp_l.resize(sz); dp_r.resize(sz); dp_l[0] = v[0]; for (int i = 1; i < sz; i++) { dp_l[i] = op(dp_l[i - 1], v[i]); } dp_r[sz - 1] = v[sz - 1]; for (int i = sz - 1; i > 0; i--) { dp_r[i - 1] = op(v[i - 1], dp_r[i]); } } S get(int i) { assert(0 <= i && i < sz); if (i == 0) return dp_r[1]; if (i == sz - 1) return dp_l[sz - 2]; return op(dp_l[i - 1], dp_r[i + 1]); } }; } // namespace cho int op(int a, int b) { return max(a, b); } using d_table = cho::lr_dp_table; 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; for (int nx : g[nw]) { if (nx == pr) continue; v.push_back(childs[nx] + 1); } v.push_back(p_val); { d_table d(v); int i = 0; for (int nx : g[nw]) { if (nx == pr) continue; self(self, nx, nw, d.get(i) + 1); i++; } } sort(v.rbegin(), v.rend()); 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(); }