#include <bits/stdc++.h>
using namespace std;
const int N = 410;
int n, head[N], pre[N], nxt[N], e, dp[N][2];
struct edge {
  int u, v;
  void read() { cin >> u >> v; }
} p[N];
void init() {
  memset(head, -1, sizeof(head));
  e = 0;
}
void addedge(int u, int v) { pre[e] = v, nxt[e] = head[u], head[u] = e++; }
void dfs(int u, int f, int &x) {
  dp[u][0] = dp[u][1] = 0;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = pre[i];
    if (v == f) continue;
    dfs(v, u, x);
    if (dp[v][0] + 1 > dp[u][0]) {
      dp[u][1] = dp[u][0];
      dp[u][0] = dp[v][0] + 1;
    } else if (dp[v][0] + 1 > dp[u][1])
      dp[u][1] = dp[v][0] + 1;
  }
  x = max(x, dp[u][0] + dp[u][1]);
}
int main() {
  init();
  cin >> n;
  for (int i = 1; i < n; ++i) {
    p[i].read();
    addedge(p[i].u, p[i].v);
    addedge(p[i].v, p[i].u);
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    int max1(0), max2(0);
    dfs(p[i].u, p[i].v, max1);
    dfs(p[i].v, p[i].u, max2);
    ans = max(ans, max1 * max2);
  }
  cout << ans << endl;
  return 0;
}
