#include <bits/stdc++.h>
using namespace std;
const int MX = (1 << 20), INF = -1 * (1 << 20);
int n, edge[MX][2], r1, r2, U, V;
vector<int> v[MX];
int dp[MX][2];
void dfs(int x, int p) {
  dp[x][0] = dp[x][1] = 0;
  int sz = v[x].size(), nxt;
  for (int j = 0; j < sz; j++) {
    nxt = v[x][j];
    if (nxt == p || nxt == r1 || nxt == r2) continue;
    dfs(nxt, x);
    if (dp[nxt][0] + 1 > dp[x][1]) dp[x][1] = dp[nxt][0] + 1;
    if (dp[x][1] > dp[x][0]) swap(dp[x][0], dp[x][1]);
  }
}
int main() {
  cin >> n;
  for (int j = 1; j < n; j++) {
    cin >> edge[j][0] >> edge[j][1];
    v[edge[j][0]].push_back(edge[j][1]);
    v[edge[j][1]].push_back(edge[j][0]);
  }
  int ans = 0;
  for (int it = 1; it < n; it++) {
    r1 = edge[it][0], r2 = edge[it][1], U = 0, V = 0;
    dfs(r1, -1);
    for (int j = 1; j <= n; j++) {
      U = max(U, dp[j][0] + dp[j][1]);
      dp[j][0] = dp[j][1] = INF;
    }
    dfs(r2, -1);
    for (int j = 1; j <= n; j++) {
      V = max(V, dp[j][0] + dp[j][1]);
      dp[j][0] = dp[j][1] = INF;
    }
    ans = max(ans, U * V);
  }
  cout << ans << endl;
}
